I’m querying shopping-carts in a shop-system, like: I need to query records of c with a column which shows the number of carts which have the same user OR the same email. So I do: This works, but the problem is that the OR is very slow, because MySQL/MariaDB doesn’t use any key in the subquery: Even forcing the index
Tag: union
SQL combining tables to single rows
A problem with combining tables into single rows. TABLE GAMES: ID player1_ID player2_ID des 11 23 68 something 82 34 23 whatever 302 13 34 mmmmmmmm TABLE PLAYERS: ID alias 23 Jeex 34 Jack 68 Jill 13 John The key I start my query with is one of the Player ID’s. I want to show all the games that Player
Error while running very long SQL query with UNION ALL operator in Vertica
This is a sample of subquery used in Vertica Query which is a string generated from the application. There are some cases when this subquery becomes huge as the number of rows with UNION ALL increases. Vertica supports this query to some extent. But when there is let’s say 3000 + UNION ALL operator used in a subquery it throws
Hive Union of two queries is giving compile error
I am not sure what is wrong with following hive query. However, it’s throwing error. I am able to run this queries individually. However, facing issues while running with union Error Answer Hive versions prior to 1.2.0 only support UNION ALL Workaround: Use UNION ALL instead of UNION, wrap all into subquery and apply distinct UNION is the same as
If null value in a Column A, then how to return the value of column B, and if also B is null, then how to move to the value of C
Have a table in Google Big Query with date, id and store columns where the goal is to keep track how many stores a customer has visited: I wish to create a SQL query which checks for date in first column (A_date). If it has a date (is not null) then keep the date If it is null then check
How to go convert to CTE
I am a little confused out a CTE works. I need to convert my statement from a rollup with a UNION to a CTE… but the CTE is a bit confusing me. Any Ideas how to approach this? Answer You can express this using a CTE as:
Performing a Union on groups of rows without the same columns. Trying to generate empty histogram bins
I am using MySQL. I have a table grades, that looks like so: I have a view that counts how many grades are in each bin, for each class using the following query. This returns: I want to add empty bins to this view, like so: So the bins increment by 5, starting at 40, and stopping at 100. My
SQL union grouped by rows
Assume I have a table like this: col1 col2 col3 col4 commonrow one two null commonrow null null three How to produce a result to look like this: col1 col2 col3 col4 commonrow one two three Thanks Answer like this, you can group by col1 and get the maximum in each group:
Combining 3 Tables and Finding Average Age in SQL
I need to combine three tables and find the average age after combining the three tables using SQL. The name of the age columns in the three tables are pr16pnk.age, pr16puf.age, and pr16yag.age. I have successfully found the results when the tables are separated, but I am having trouble combining the results. Listed below is the code that I used.
Append Group with data from another table based on its existence in first table
I have a table like this I have another table with these data Based on the second table I need to find which phases are missing for each Project codes So I need to get a result like this I tried cross join it doesn work since its creating 4 entries for each one item in the first table. So