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
Tag: subquery
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
SQL – Count rows based on matching columns and value range
Please see below query using T-SQL with SSMS. There are three tables: B, G and L. B has a column Bname G has 2 columns Gname, Gross L has 2 columns Bname, Gname Gross column is an INT ranging …
Select longest duration time (data type field) and client name SQL
I have these tables: CREATE TABLE Client ( client_id NUMBER(10) NOT NULL PRIMARY KEY, name VARCHAR(50) NOT NULL, address VARCHAR(50) NOT NULL ); CREATE TABLE Projects ( project_id …
How to use the results of one query in the next query?
I have read answers here but I am still not quite sure how I would do this regarding two columns of a table and more than one result per query. So, the first query would look like this in my Node app: …
Mysql subquery in where clause that returns comma separated value
I’m not really good at subqueries, here’s the sample tables that I have. table customers ===================== id | name | order_ids 1 | John | 1,2 table orders ===================== id | name 1 …
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
ms access, need to get all rows with a distinct column
I have a table called “parts” which stores information on electrical connectors including contacts, backshells etc. all parts that are part of an assembly have a value in a column called &…
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