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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.