haku87 Posted February 7, 2008 Share Posted February 7, 2008 I got three tables tblmcq, tblsaq,tblessay. Each table contain a column called quizid I will like to select all data from these three tables where quizid = 3. How to write the mysql statement? Quote Link to comment https://forums.phpfreaks.com/topic/89876-select-data-from-more-than-1-table/ Share on other sites More sharing options...
pdkv2 Posted February 7, 2008 Share Posted February 7, 2008 use the join Quote Link to comment https://forums.phpfreaks.com/topic/89876-select-data-from-more-than-1-table/#findComment-460603 Share on other sites More sharing options...
haku87 Posted February 7, 2008 Author Share Posted February 7, 2008 Wat u mean? I mean i need to echo out all data from three tables Quote Link to comment https://forums.phpfreaks.com/topic/89876-select-data-from-more-than-1-table/#findComment-460604 Share on other sites More sharing options...
pdkv2 Posted February 7, 2008 Share Posted February 7, 2008 Wat u mean? I mean i need to echo out all data from three tables Have you selected the data from database ??? using join query ? Quote Link to comment https://forums.phpfreaks.com/topic/89876-select-data-from-more-than-1-table/#findComment-460612 Share on other sites More sharing options...
priti Posted February 7, 2008 Share Posted February 7, 2008 I got three tables Each table contain a column called quizid I will like to select all data from these three tables where quizid = 3. How to write the mysql statement? how are you retrieving you info from these three tables. with a help of single query ?? Quote Link to comment https://forums.phpfreaks.com/topic/89876-select-data-from-more-than-1-table/#findComment-460623 Share on other sites More sharing options...
Zane Posted February 7, 2008 Share Posted February 7, 2008 SELECT * FROM table1 AS a table2 AS b table3 AS c WHERE a.quizid = 3 AND b.quizid = 3 AND c.quizid = 3 Quote Link to comment https://forums.phpfreaks.com/topic/89876-select-data-from-more-than-1-table/#findComment-460628 Share on other sites More sharing options...
aschk Posted February 7, 2008 Share Posted February 7, 2008 Are the 3 tables related to each other? Or do they just "happen" to all contain a column called quizid If they're related tet's try something more semantically correct... SELECT tm.*, ts.*, te.* FROM tblmcq tm JOIN tblsaq ts ON ts.quizid = tm.quizid JOIN tblessay te ON te.quizid = tm.quizid WHERE tm.quizid = 3; If they're UNRELATED (i.e. the tables DON'T join on quizid) then you need to do a UNION specifying the EXACT same number of columns e.g. SELECT column1, column2, column3 FROM tblmcq WHERE quizid = 3 UNION SELECT column1, column2, column3 FROM tblsaq WHERE quizid = 3 SELECT column1, column2, column3 FROM tblessay WHERE quizid = 3 Quote Link to comment https://forums.phpfreaks.com/topic/89876-select-data-from-more-than-1-table/#findComment-460633 Share on other sites More sharing options...
Zane Posted February 7, 2008 Share Posted February 7, 2008 wow...I learn something everyday never knew about UNION before I'm not the greatest SQL person in the world Quote Link to comment https://forums.phpfreaks.com/topic/89876-select-data-from-more-than-1-table/#findComment-460807 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.