Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL query return data from multiple tables
    primarykey
    data
    text
    <p>I would like to know the following:</p> <ul> <li>how to get data from multiple tables in my database?</li> <li>what types of methods are there to do this?</li> <li>what are joins and unions and how are they different from one another? </li> <li>When should I use each one compared to the others?</li> </ul> <p>I am planning to use this in my (for example - PHP) application, but don't want to run multiple queries against the database, what options do I have to get data from multiple tables in a single query?</p> <p>Note: I am writing this as I would like to be able to link to a well written guide on the numerous questions that I constantly come across in the PHP queue, so I can link to this for further detail when I post an answer.</p> <p>The answers cover off the following:</p> <ol> <li><a href="https://stackoverflow.com/questions/12475850/how-can-an-sql-query-return-data-from-multiple-tables/12475851#12475851">Part 1 - Joins and Unions</a></li> <li><a href="https://stackoverflow.com/questions/12475850/how-can-an-sql-query-return-data-from-multiple-tables/12492267#12492267">Part 2 - Subqueries</a></li> <li><a href="https://stackoverflow.com/questions/12475850/how-can-an-sql-query-return-data-from-multiple-tables/12508381#12508381">Part 3 - Tricks and Efficient Code</a></li> <li><a href="https://stackoverflow.com/a/12542115/1450077">Part 4 - Subqueries in the From Clause</a></li> <li><a href="https://stackoverflow.com/a/12586263/1450077">Part 5 - Mixed Bag of John's Tricks</a></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload