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
8 Antworten
+ 1
Vaishali Bishtaniya look up the MINUS keyword to see if that helps solve the task.
+ 1
I might be able to help if you show what you tried.
+ 1
A join should work if used correctly. Show your query here so I can help correct it.
0
Brian...not worked
0
I tried using joins
0
M texting in ur inbox sir
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.
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.