Click here to Skip to main content
15,907,913 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi all...
i have two tables like one is
uid    name
1      peter
2      parker
3      jhon
4      watson
5      backinsale

and another table like:
uid    date
1      2011-11-26
2      2011-11-26

here i need to get records in which uid is not there in second table that is like
uid    name
3      jhon
4      watson
5      backinsale 

i written query like
SQL
select * from tbl1,tbl2 where tbl1.uid!=tbl2.uid


but it is not return correct result set
can any one help me please
thanks in advance...
Posted

try this one.

SELECT t2.uid, t2.name FROM t1
RIGHT JOIN t2 on t2.uid = t1.uid
WHERE t2.date IS NOT NULL


Regards,
Eduard
 
Share this answer
 
v2
Comments
tulasiram3975 28-Nov-11 2:35am    
Thanks For The Help..
[no name] 28-Nov-11 2:41am    
welcome
Try using LEFT JOIN[^] like this:
SQL
SELECT *
FROM tbl1
LEFT JOIN tbl2
ON tlb1.uid = tbl2.uid
WHERE tbl2.uid = NULL

OP remarked that the result was empty and he is right the statement should be:
SQL
SELECT tbl1.uid, tbl1.name
FROM tbl1
LEFT JOIN tbl2
ON tbl1.uid = tbl2.uid
WHERE tbl2.uid IS NULL

I also changed the SELECT as otherwise the NULL columns of tbl2 are also shown.
 
Share this answer
 
v2
Comments
Mehdi Gholam 26-Nov-11 5:34am    
I was going to post the same, 5!
tulasiram3975 26-Nov-11 5:35am    
it is also not returning result set it gives me answer as
MySQL returned an empty result set (i.e. zero rows).
André Kraak 27-Nov-11 5:01am    
You are right, I found the error and I updated the solution.
tulasiram3975 26-Nov-11 5:37am    
It Wont Working i need
uid name
3 jhon
4 watson
5 backinsale
these records.......
thank you
RaisKazi 26-Nov-11 6:23am    
Have a look at my answer.
Try as below Query.
SQL
Select * from Table1 T1
where T1.uid not in (Select T2.uid from Table2 T2);
 
Share this answer
 
Comments
tulasiram3975 28-Nov-11 2:31am    
thank you Very Much..
RaisKazi 28-Nov-11 2:32am    
Welcome.
SELECT dbo.test1.uid, dbo.test1.name
FROM dbo.test1 left JOIN
dbo.test2 ON dbo.test1.uid = dbo.test2.uid
where dbo.test2.uid is null
 
Share this answer
 
Comments
tulasiram3975 28-Nov-11 2:35am    
Thanks For The Help..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900