Skip to content
Advertisement

Tag: subquery

put on duplicate key update in MySQL

let’s say i have 2 tables table shipping id origin order_id createdAt product_id amount 1 1 11 2020-12-22 234 2000 2 1 11 2020-12-22 235 3000 3 1 11 2020-12-22 236 4000 4 2 12 2020-12-22 236 3000 5 2 12 2020-12-22 235 2100 6 3 13 2020-12-22 236 2200 7 3 13 2020-12-22 239 3400 8 4 14 2020-12-22

Return in which or statement results are from SQL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 1 year ago. Improve this question I’m having the following SQL statement, to return worksheets that teachers have liked, and worksheets that teachers made by themselves. It’s working fine, but now

subquery shows more that one row group by

I am trying to get the data for the best 5 customers in a railway reservation system. To get that, I tried getting the max value by summing up their fare every time they make a reservation. Here is the code. this throws the error:[21000][1242] Subquery returns more than 1 row If I remove the group by from the subquery

Select max date per year

I have the table as follows: And I’d like to select the max date for every year per user, so the result would be like: Some help? Thank you! Answer Just use aggregation: If you have more columns that you want, then use distinct on:

How to sort and group data in request?

I have got table. It have some duplicates in purchaseNumber. I need select from this table only newest records for processing. In other words I need to: group elements by purchaseNumber sort them by docPublishDate and select newest. if any of elements in group is have status parsing_status true (suppose it was newest from step 2) any elements SHOULD NOT

Advertisement