Forum Moderators: open

Message Too Old, No Replies

SQL Select from tbl1 based on criteria in tbl2

         

UFfan

6:41 pm on Jul 31, 2007 (gmt 0)

10+ Year Member



I know this is not a SQL board and I appoligize for posting my question here but I could not find the correct place on this board. My question: I have a two tables and I need to select from 1 table based on criteria in table 2. Tables names tblPark, tblParkAttribute. I am joining the two tables with a fk_tblParkAttribute.tblPark.

UFfan

6:55 pm on Aug 1, 2007 (gmt 0)

10+ Year Member



This appears to work.

SELECT tblPark.id FROM tblPark, tblParkAttributes WHERE tblPark.fk_ParkAttributes=tblParkAttributes.id AND tblParkAttributes.something=YES AND tblParkAttributes.somethingelse=YES order by tblPark.id

coopster

1:50 am on Aug 8, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I know this is not a SQL board and I appoligize for posting my question here but I could not find the correct place on this board.

Actually, you are in the right spot, UFfan. Welcome to WebmasterWorld. So, did the query work as you expected? Did you get the expected result set?

syber

12:30 pm on Aug 8, 2007 (gmt 0)

10+ Year Member



If you are using table 2 only for criteria, then it is more efficent to use a Sub Query than a Join.


SELECT id
FROM tblPark
WHERE fk_ParkAttributes = SELECT (id FROM tblParkAttriutes
WHERE something=YES AND somethingelse=YES)
ORDER by id

UFfan

8:01 pm on Aug 10, 2007 (gmt 0)

10+ Year Member



Thanks for the replies... Yea, coopster, the query work fine but I think I am going to try syber idea and see if that is more efficient.