How to use a CASE statement? - case

My goal is to create columns based upon dates found in different tables.
I used a union to combine the tables, which allowed me to pull a final set and their observation.
I have tried inserting the following case statement on both sides of the union, but neither worked. The error is that one side of the union can not recognize the other table and throws an error.

Related

Kusto: Query execution has exceeded the allowed limits (80DA0003):

There are three tables mentioned below, I eventually want to bring in a field from Table3 to Table1 (but the only way to join these two tables is via a common field present in Table2)
Table 1: Application Insights-30 days data (datasize ~4,000,000)
Table 2: Kusto based table (datasize: 1,080,153)
Table 3: Kusto based table (datasize: 38,815,878)
I was not able to join the tables directly, So, I used various filter conditions, distinct operators and split the month data to 4 weeks and then used union to join all 3 tables and got the resultant table.
However, now I am unable to perform any operations on the resultant table (even |count doesn't work)
I get the following error
Query execution has exceeded the allowed limits (80DA0003):
Any help in handling such cases would be helpful
Please check article how to control the query limits:
https://learn.microsoft.com/en-us/azure/data-explorer/kusto/concepts/querylimits#limit-on-result-set-size-result-truncation
When using the join operator, make sure that the table with fewer rows is the first one (left-most in query).
See more Best Practices here.

How to define a cursor, when we have a common column between two tables without giving alias

I have 4 tables: T1,T2,T3 and T4. All of them have more than 50 columns.There are few columns which are common between above 4 tables. Lets say C1 is present in all 4 tables. There are few more columns which are common between above multiple tables.
Now if i decalre a cursor CUR1 as:
cursor CUR1 as select * from T1,T2,T3,T4 where <join conditions for 4 tables>;
I am gettign error while fetching the data due to ambiguity of common column C1.
Is it possible to avoid the error without listing each and every column names and their alias?
Somehow can i append the any idicator for all the column of table without specifying alias for every columns?
Thanks.
Not possible, as far as I can tell. However, if you frequently use the same FROM ... WHERE clause, you could create a view (therefore, do it once, specifying every single column - with its alias - in order to avoid the error) and then use the view in your SELECT statements.

Moving rows in sqlite database

I have a table that is actually a ranking list. I want to give user a chance to rearrange that top the way he wants, ergo, allow him to move the rows in that table. Should I create a separate column that would hold the place, or can it be done using embedded order in table?
The documentation says:
If a SELECT statement that returns more than one row does not have an ORDER BY clause, the order in which the rows are returned is undefined.
(This is true for all SQL databases.)
So you cannot rely on the order that the rows happen to be stored in; you have to use some value in some table column.

UNION of tables using bigquery LegacySQL

I'm trying without luck to do a query to retrieve the union two tables of events using legacySQL, as standardSQL is not yet supported on data studio.
In standardSQL that would be something like:
SELECT
*
FROM
`com_myapp_ANDROID.app_events_*`,
`com_myapp_IOS.app_events_*`
However, in legacySQL I get an error when trying to refer app_events_*. How do I include all the tables of my events, so I can filter it afterwards on data studio if I can't use the wildcard?
I've tried something like:
select * from (TABLE_QUERY(com_myapp_ANDROID, 'table_id CONTAINS "app_events_"'))
But not sure if this is the right approach, I get:
Cannot output multiple independently repeated fields at the same time.
Found user_dim_user_properties_value_index and event_dim_date
Edit: in the end this is the result of the query, as you can't use directly FLATTEN with TABLE_QUERY:
select
*
from
FLATTEN((SELECT * FROM TABLE_QUERY(com_myapp_ANDROID, 'table_id CONTAINS "app_events"')),user_dim.user_properties),
FLATTEN((SELECT * FROM TABLE_QUERY(com_myapp_IOS, 'table_id CONTAINS "app_events"')),user_dim.user_properties)
Table wildcards don't work in legacy SQL as you have guessed so you have to use the TABLE_QUERY() function.
Your approach is right but the first parameter in the TABLE_QUERY function should be the dataset name not the first part of the table name. Assuming your dataset name is app_events that would look like this:
TABLE_QUERY(app_events,'table_id CONTAINS "app_events"')
In legacySQL the union table operator is comma
select * from [table1],[table2]
For TABLE_QUERY you would include the dataset name as first param, and the expression for the second
select * from (TABLE_QUERY([dataset], 'table_id CONTAINS "event"'))
to read more how to debug TABLE_QUERY read this linked answer
The Web UI automatically flattens you the results, but when there are independent repeated fields you need to flatten with the FLATTEN wrapper.
It takes two params, table, and repeated field eg: FLATTEN(table, tags)
Also if TABLE_QUERY is involved you need to subselect probably like
select
*
from
FLATTEN((SELECT * FROM TABLE_QUERY(com_myapp_ANDROID, 'table_id CONTAINS "app_events"')),user_dim.user_properties)
That particular issue you are experiencing is not UNION related - you will see same error message even with just one table if the table has multiple independently repeated fields and you are trying to output them at once. This scenario is specific to Legacy SQL and can be resolved with use of FLATTEN clause
At the same time, most likely you don't actually mean to use SELECT * which cause those repeated fields to be in output all at the same time. If you can narrow down your output list - you have slight chance to address it - but if still few independently repeated fields are in output - you can use FLATTEN technique

ERROR:-528 MEssage: [Informix .NET provider][Informix]Maximum output rowsize (32767) exceeded

I face the following exception when i try to get data from table with the following structure:
ERROR:-528 MEssage: [Informix .NET provider][Informix]Maximum output
rowsize (32767) exceeded.
CREATE TABLE dr66req
(
req_ser SERIAL PRIMARY KEY,
req_desc LVarChar(32739),
);
Ref:
The total number of bytes that this statement selects exceeds the
maximum that can be passed between the database server and the program.
Try following-
1) Make sure that the columns selected are the ones that you intended.
2) Check that you have not named some very wide character column by
mistake, neglected to specify a substring, or specified too long a
substring. If the selection is what you require, rewrite this SELECT
statement into two or more statements, each of which selects only some
of the fields.
3) If it is a join of several tables, you might best select
all desired data INTO TEMP; then select individual columns of the
temporary table.
4)If this is a fetch via a cursor in a program, you
might revise the program as follows.
First, change the cursor to select only the ROWID of the desired row.
Second, augment the FETCH statement with a series of SELECT statements, each of which selects one or a few columns WHERE ROWID = the saved row ID.

Resources