I have to write a query which will return the latest timestamp column’s value from a table if rows exist. If there is no row(s) in table then it return the default value. I have write the following query in MS-SQL which is working fine for me. But , now I need to write this query in MySQL. I have
Tag: union-all
UNION ALL Slower than N queries
This question is following this question where I wanted to select the MAX value of multiples fields while retrieving each row. The accepted answer with UNION ALL worked like a charm but I now have some scaling issues. To give some context, I have more than 3 million rows in my matches table and the filters used in the WHERE
how to sum two columns from different tables MySQL
I need to sum the data from two different columns located in different tables and grouped by session_id….. I need to sum the column of spent_points + price_points grouped by session_id this is the result i hope to get I have tried with this query but I have only managed to group the data but I have not been able
pgsql merge two json arrays
I have to select two type of result set from a table and merge them in single json array like Its saying syntax error I believe due to order by. I need to return this in json array so I am trying like this Its retiring two json arrays i.e. obvious, How can I make this in single array Thanks,
How do I merge two SELECT queries with different WHERE clauses
I’m trying to write query on two different selects with different WHERE clause and using GROUP BY. I browsed for examples but mine is different since I have multiple fields for SELECT. Here is example data: These are the queries I would like to merge: I tried 2 methods as under: Both give Error: Please guide Answer seems like you
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:
If a column is not null then convert into a row for multiple columns
I have a table like below where I looking to transpose col4 col5 and col6 into rows but in a specific pattern that I listed below col1 col2 col3 col4 col5 col6 a b c 500 200 w x y 1000 300 z g h 200 600 I want to convert it to the following col1 col2 col3 col4 col5
union all two table instead of join
I have several table which I can not join them as it gets really complicated and bigquery is not able to process it. So I am trying to union all tables and then group by. I have an issue during this process. I have two tables called t1 and t2 with below headers, they don’t have null values: so in
Select list as column in Oracle SQL
I would like to append a few rows to an already existing table (15 rows to be precise). What is the quickest way to do this? This works, but it seems redundant. I was wondering if there’s a solution along the lines of: Please note that I want to preserve the leading zeros for each element in my list. This
UNION ALL not combining rows
I have this table called “valores_indices” where it imports stocks values every 1 hour, I need to get the values from each monitored stock at 8am and 6pm, those being respectively my “vlrAberto” and “vlrFechado” selects I don’t get why these are not merging, I’ve done it before, any help would be appreciated since I’m running out of ideas, I’ve