
Originally Posted by
bullzzz
I do not need to join data from 2 tables where tableX.ID=tableY.ID. The only set of data important to me are only data from tableY.
then instead of SELECT * you would select only those columns you want from table Y
so instead of
Code:
select * from tableX, tableY
where tableX.id=tableY.id
you would say
Code:
select tableY.foo
, tableY.bar
, tableY.qux
from tableY
, tableX
where tableY.id
= tableX.id
thus listing only columns from tableY after the SELECT
the above is an inner join and it can also be written like this --
Code:
select tableY.foo
, tableY.bar
, tableY.qux
from tableY
inner
join tableX
on tableY.id
= tableX.id
you mentioned you didn't need the join, but you do 
you have to somehow specify that you want only those rows from Y which are also in X, and the easiest way to do that is with a join
another way is with a subquery --
Code:
select tableY.foo
, tableY.bar
, tableY.qux
from tableY
where exists
( select 1
from tableX
where tableX.id
= tableY.id )
this might actually be more understandable to some people's way of thinking, but -- and this is a good thing -- the subquery is actually executed by the database engine as a join
Bookmarks