tags:

views:

88

answers:

3
SELECT column1 FROM table1 WHERE
     EXISTS ( SELECT column1 FROM table2 WHERE table1.column1 = table2.column1 );
A: 

Hi, try it like this

SELECT column1 
FROM table1
 INNER JOIN table2 ON table2.column1 = table1.column1
IordanTanev
This makes no difference, except for probably now returning multiple rows if table2 is a child of table1. So then you'd need DISTINCT to fix it back to how EXISTS works...
gbn
yes the query i wrote is the same as yours but more efficient. IF your query doesn't work please tell what is the problem. Some table schemes will help too
IordanTanev
@IordanTanev: can you show me where it say JOIN is more efficient then EXISTS please? For my side, see these http://stackoverflow.com/questions/2019958 or this http://stackoverflow.com/questions/2177346/
gbn
Mr Tanev, it may be more efficient but it doesn't do the same thing, as gbn pointed out. Doing the wrong thing quickly is not an improvement on doing the right thing slowly, although many managers seem to think it is.
Brian Hooper
A: 

Unless I miss something, isnt this just a normal join?

select table1.column1 from table1, table2 where table1.column1 = table2.column1;
Fadrian Sudaman
No, not really. See my comment to lordanTanev's answer. You haven't posted a JOIN anyway.
gbn
JOIN keyword is introduced in ANSI92, but prior to that JOIN is done through where clause. Internally it may be interpreted differently from INNER JOIN (i dont know), but to my knowledge this is still well supported and recognize as JOIN using the traditional syntax?
Fadrian Sudaman
Found this post here that discuss about what I said abovehttp://stackoverflow.com/questions/334201/why-isnt-sql-ansi-92-standard-better-adopted-over-ansi-89
Fadrian Sudaman
A: 

answer:

SELECT column2 FROM table1 WHERE
     EXISTS ( SELECT column2 FROM table2 WHERE table1.column2 = table2.column2 );
cache
-1: not the answer.
John Saunders
out of minddddddddddd..........atleast you get one vote in this question
Pranay Rana
Another possible answer is: "Using a keyboard".
Nubsis
@cache: Where did column2 come from?
Mark Bannister