erme Posted January 27, 2010 Share Posted January 27, 2010 Hi, New to SQL so bare with me! I have 4 tables and want to grab info from all of them in the same way as if all the tables info were in 1 table. Basically want something like this SELECT * FROM Table1 & Table2 & Table3 & Table Where blah blah blah Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/189924-select-from-2-tables/ Share on other sites More sharing options...
premiso Posted January 27, 2010 Share Posted January 27, 2010 SELECT * FROM table1, table2, table3, table4 WHERE condtion=something You may want to look into joins, but yea. There you go. Quote Link to comment https://forums.phpfreaks.com/topic/189924-select-from-2-tables/#findComment-1002140 Share on other sites More sharing options...
RussellReal Posted January 27, 2010 Share Posted January 27, 2010 to bridge off of what premiso said, you'd do like WHERE table1.id = table2.id etc etc Quote Link to comment https://forums.phpfreaks.com/topic/189924-select-from-2-tables/#findComment-1002141 Share on other sites More sharing options...
erme Posted January 27, 2010 Author Share Posted January 27, 2010 to bridge off of what premiso said, you'd do like WHERE table1.id = table2.id etc etc This doesn't seem to work. Am I doing something wrong? SELECT DISTINCT County FROM Table1, Table2 WHERE Table1.County = Table2.County Order by County ASC Quote Link to comment https://forums.phpfreaks.com/topic/189924-select-from-2-tables/#findComment-1002602 Share on other sites More sharing options...
RussellReal Posted January 27, 2010 Share Posted January 27, 2010 no that looks right.. try this.. SELECT * FROM Table1 JOIN Table2 ON (Table1.County = Table2.County) WHERE ETC ETC ETC Quote Link to comment https://forums.phpfreaks.com/topic/189924-select-from-2-tables/#findComment-1002616 Share on other sites More sharing options...
erme Posted January 27, 2010 Author Share Posted January 27, 2010 Still dosent seem to work Quote Link to comment https://forums.phpfreaks.com/topic/189924-select-from-2-tables/#findComment-1002623 Share on other sites More sharing options...
erme Posted January 27, 2010 Author Share Posted January 27, 2010 Do the field names need to be different in each table? Like County1 and County2 Quote Link to comment https://forums.phpfreaks.com/topic/189924-select-from-2-tables/#findComment-1002638 Share on other sites More sharing options...
RussellReal Posted January 27, 2010 Share Posted January 27, 2010 nope.. is your table names literally "Table1" and "Table2"? Quote Link to comment https://forums.phpfreaks.com/topic/189924-select-from-2-tables/#findComment-1002644 Share on other sites More sharing options...
erme Posted January 27, 2010 Author Share Posted January 27, 2010 One's called Locations, other one is called Places. But have been changing them from Table1 .. when testing Quote Link to comment https://forums.phpfreaks.com/topic/189924-select-from-2-tables/#findComment-1002649 Share on other sites More sharing options...
RussellReal Posted January 27, 2010 Share Posted January 27, 2010 use the correct table names in the query. Quote Link to comment https://forums.phpfreaks.com/topic/189924-select-from-2-tables/#findComment-1002651 Share on other sites More sharing options...
erme Posted January 27, 2010 Author Share Posted January 27, 2010 Even if I do this it doesn't work SELECT * FROM Locations, Places where as this works: SELECT * FROM Locations Quote Link to comment https://forums.phpfreaks.com/topic/189924-select-from-2-tables/#findComment-1002654 Share on other sites More sharing options...
erme Posted January 27, 2010 Author Share Posted January 27, 2010 Got it working. For some reason UNION worked Quote Link to comment https://forums.phpfreaks.com/topic/189924-select-from-2-tables/#findComment-1002657 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.