MySQL Need help constructing query: join multiple tables into single row
Posted
by Jed Daniels
on Stack Overflow
See other posts from Stack Overflow
or by Jed Daniels
Published on 2010-03-20T23:37:20Z
Indexed on
2010/03/20
23:41 UTC
Read the original article
Hit count: 370
Hello stackoverflowers,
Forgive me if this question has been asked and answered, I've searched and found a few that look similar but I'm too much of a novice with SQL to adapt them to my needs. Also forgive me if I don't use the correct terminology, I know it can be annoying when someone asks a question and they don't even know enough to be able to ask for what they need.
I'm helping a friend gather some data, and need to perform a query that results in a single row per record, but instead I get multiple rows. Here is an example of what I'm querying right now (simplified, hopefully not too much):
SELECT * FROM `table_one` AS t1
INNER JOIN `table_two` AS t2 ON t1.id = t2.id
INNER JOIN `table_three` AS t3 ON t1.id = t3.id
WHERE 1
The result is:
id text number
5 Subtotal 17
5 Tax 3
5 Total 20
What I need is to create a query that results in something more like this:
id text number text number text number
5 subtotal 17 Tax 3 Total 20
Any assistance/guidance would be much appreciated.
Thanks!
--jed
© Stack Overflow or respective owner