beennn Posted March 6, 2013 Share Posted March 6, 2013 How can I find a value in; table1 column1 which is the same as table2 column1table1 column2 which is the same as table2 column1 in the same query? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 6, 2013 Share Posted March 6, 2013 One way is to use a subquery, e.g.; SELECT * FROM table1 WHERE column1 IN (SELECT column1 FROM table2) You may also want to use a join instead, look up joins to see if that's what you're trying to do. Link to comment Share on other sites More sharing options...
beennn Posted March 6, 2013 Author Share Posted March 6, 2013 (edited) Thank you. Mm. I'm a bit lost, what you've posted is what I was after, but I'm still a bit stuck with something else I'm trying do. I have table1 which contains foreign keys to 3 other tables, table2 table3 and table4; Can I select specific columns inside of table2 table3 and table4, matching the ID in each of these tables to those in table1, and output the result in one go? So like: SELECT column2 FROM table2 WHERE column1 = table1.column1 = 1;SELECT column2 FROM table3 WHERE column1 = table1.column2 = 3;SELECT column2 FROM table4 WHERE column1 = table1.column4 = 6; in one query? Edited March 6, 2013 by beennn Link to comment Share on other sites More sharing options...
justsomeguy Posted March 6, 2013 Share Posted March 6, 2013 You'll want to use a join for that. Link to comment Share on other sites More sharing options...
beennn Posted March 6, 2013 Author Share Posted March 6, 2013 (edited) EDIT: Sorry, got it. Accidently removed the inner join. Thank you very much for the help, all sorted now I think Edited March 6, 2013 by beennn Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now