0

Record matching through sql

Two datasets are given.. with 3 fields( product, order, qnty). Product+ order is primary key. How to find number of order present in dataset 1 but missing in 2 only through sql

18th Nov 2022, 6:18 AM
Vaishali Bishtaniya
8 odpowiedzi
+ 1
Vaishali Bishtaniya look up the MINUS keyword to see if that helps solve the task.
18th Nov 2022, 7:58 AM
Brian
Brian - avatar
+ 1
I might be able to help if you show what you tried.
18th Nov 2022, 8:03 AM
Brian
Brian - avatar
+ 1
A join should work if used correctly. Show your query here so I can help correct it.
20th Nov 2022, 8:11 PM
Brian
Brian - avatar
0
Brian...not worked
18th Nov 2022, 8:01 AM
Vaishali Bishtaniya
0
I tried using joins
19th Nov 2022, 4:19 AM
Vaishali Bishtaniya
0
M texting in ur inbox sir
24th Nov 2022, 4:45 AM
Vaishali Bishtaniya
0
To find the number of orders present in the first dataset but missing in the second dataset, you can use the following SQL query: SELECT COUNT(*) FROM dataset1 WHERE (product, order) NOT IN (SELECT product, order FROM dataset2) This query uses a subquery to select all unique pairs of product and order values from the second dataset. The outer query then counts the number of rows in the first dataset that have a product and order combination that is not present in the second dataset. This will give you the number of orders present in the first dataset but missing in the second dataset.
7th Dec 2022, 3:33 PM
Calviղ
Calviղ - avatar
0
Alternatively, you can use a LEFT JOIN to achieve the same result. The following query uses a LEFT JOIN to join the first dataset to the second dataset, and then uses a WHERE clause to filter out any rows where the product and order combination exists in both datasets: SELECT COUNT(*) FROM dataset1 LEFT JOIN dataset2 ON dataset1.product = dataset2.product AND dataset1.order = dataset2.order WHERE dataset2.product IS NULL AND dataset2.order IS NULL This query will also give you the number of orders present in the first dataset but missing in the second dataset.
7th Dec 2022, 3:34 PM
Calviղ
Calviղ - avatar