Jump to content

Select data from more than 1 table..


haku87

Recommended Posts

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 ??

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.