1

I have 2 tables in Mysql

Table 1 --

Id     candidate_id     resume

25      100                   hjksdf.jpg

26      101                   hdd.docx

29      102                    hf.docx

30      103                   hsdfh.docx

Table 2 --

resumes_sent_id     client_id     candidate_id       date   

1                                43                100           2014-03-14 03

2                                43                101           2014-03-15 03

I need to join these two tables where client_id 43 after joining I need only "unjoined" records. If I join I can get candidate_id which values have unique 100,101. But in my output I need those data records which have 102,103 it means except unique values of joining.

Based on t2 where client_id is 43 there are two values 100 and 101 but I want to filter unmatched values like 102.

1

5 Answers 5

2

Try this

SELECT table1.*
FROM table1 LEFT JOIN table2 ON table2.candidate_id=table1.candidate_id
WHERE table2.candidate_id IS NULL and t2.client_id=43
Sign up to request clarification or add additional context in comments.

Comments

1

You got to use Outer join if you want unmatched records

select your column names from table1 t1 outer join table2 t2 on t1.candidate_id=t2.candidate_id 

Comments

0

Use a left join and test for null

select * from table1 t1
left join table2 t2 on t1.candidate_id=t2.candidate_id
where t2.candidate_id is null

left join returns all rows from the first table with t2 values where there is a match or nulls where there is no corresponding t2 row. From that result you want all rows where there was no match, resulting in t2.candidate_id being null.

Comments

0

Hope this help....

IF you use not equal sign in your query then you get a result of 6 rows

SELECT     * FROM  TABLE1 T1 INNER JOIN TABLE2 T2 ON T2.CLIENT_ID= 43 AND  T1.CANDIDATE_ID  T2.CANDIDATE_ID

BUT it includes 2 rows having 100,101 due to join

....IF YOU manually wanted to remove 100,101 id from result then got for this query..

SELECT * FROM TABLE1 T1 INNER JOIN TABLE2 T2 ON T2.CLIENT_ID= 43 AND T1.CANDIDATE_ID  T2.CANDIDATE_ID AND T1.candidate_id NOT IN(101,100)

Thanks

Comments

0

Use thr following code:

SELECT * FROM `Table 1` t1 
    LEFT JOIN `Table 2` t2 
    ON t1.candidate_id=t2.candidate_id 
    WHERE t2.candidate_id IS NULL

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.