Lets say I have 2 tables T1 and T2. I need all values from table T1 that does not exist in table T2. How would that SQL look like?
T1: T2:
T1.ID T2.ID
T1.Value T2.T1ID
T1.Date T2.Value
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You mean you need every
T1.Valuethat does not match anyT2.Value?If so, you can use something like this:
MySQL, however, may not be very good at finding optimal plan for executing this query, so if your measurements show a performance problem, try something like this:
Note the DISTINCT clause, which ensures T1 rows are not “multiplied” by the JOIN.
Or even like this, if you only care about
T1.Value: