Comments
1 comment
-
Hi @kkgunner
Thank you for reaching out on the Redgate forums.
Am I correct in saying that this is not related to any of our products, but instead is a general SQL query?
We may not be able to provide as much assistance as perhaps a more SQL-language centric forum/site.
Having said that, looking at your query I can possibly assist with chunking down some of your logic requirements.
* You want to fetch all records in table B that match to table C
This can probably be covered with an INNER JOIN - it returns matches that exist in both tables
e.g. SELECT * from b INNER JOIN c on c.email = b.email
this would return all records from b where there is a matching email in c
Then using a case statement to check the following logic switches
* the records exists in both a & b
* the record exists in only b
* the record exists in only a
I made a simple script that looks like it may come close to your requirements.
It returns first_name, last_name, prodct_name & product_number and does a CASE statement to work out a result value.
It does a FULL OUTER JOIN that includes all records in a & b
It does an INNER JOIN that includes only matched records in b & c
SELECT a.firstname, a.lastname, b.productname, b.productnumber, CASE WHEN EXISTS (SELECT * FROM a WHERE a.email = b.email) THEN 'received - in both a & b' WHEN a.email is NULL THEN 'received - in b but not in a' WHEN b.email IS NULL THEN 'not received - in a but not in b' ELSE 'null' END AS result FROM B FULL OUTER JOIN a ON a.email = b.email INNER JOIN c ON c.email = b.email
May not be a full solution, but hopefully gets you moving forward with your inquiry.
We can't provide much other support if this is not related to a Redgate product, but may guide you into some other SQL communities who can assist further.
Add comment
Please sign in to leave a comment.