The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> MySQL Help
|
Help needed finding data from 4 tables
Discuss Help needed finding data from 4 tables in the MySQL Help forum on Dev Shed. Help needed finding data from 4 tables MySQL Help forum discussing administration, SQL syntax, and other MySQL-related topics. MySQL is an open-source relational database management system (RDBMS).
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 17th, 2012, 06:30 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 26 m 34 sec
Reputation Power: 0
|
|
|
Help needed finding data from 4 tables
Hi There
I have searched and tried to locate this answer before posting.
I have a MYSQL problem
I have 4 tables with lots of different columns.
All 4 tables have the same ID column, a unique reference number:
Each table has one Row that point to the same ID
My problem is:
I need query all 4 tables and get the row back using the ID column
How do i do this.
Im using
PHP Code:
SELECT * FROM table1, table2, table3, table4 WHERE table1.ID = '$record'
This pulls other rows i don't want.
I just want the 4 rows with the same ID
How can i do this?
|

December 17th, 2012, 07:07 AM
|
|
|
|
Hm, where to begin...
OK. In your own time read up on JOINs and UNIONs. Then find out what DDLs are in relation to MySQL. Then, if you're still stuck, come back to us with a more structured question, and an indication of what the output should actually look like.
|

December 17th, 2012, 07:22 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 26 m 34 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by cafelatte Hm, where to begin...
OK. In your own time read up on JOINs and UNIONs. Then find out what DDLs are in relation to MySQL. Then, if you're still stuck, come back to us with a more structured question, and an indication of what the output should actually look like. |
Honest ive been reading and trying everything, im stuck.
I ve hit a brick wall.
All the JOIN answers relate to specific columns in each table,
but i have so many columns i can possible add all columns to the query. There has to be a simpler way.
I need a one liner to look up all 4 tables, and bring me back all the column data for that record: ID=165456
So something like:
Get ALL COLUMN DATA with ROW ID = 165456 from all the 4 TABLES
*****
There is only one row in each table with the same ID Number
Still trying to solve this one.
|

December 17th, 2012, 07:46 AM
|
|
|
|
All of your tables share one, and only one, column in common. That's the criteria upon which they should be JOINed.
An inability to name all the columns in your query points to either poorly designed tables or chronic laziness.
|

December 17th, 2012, 08:19 AM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
normally i don't like to just provide a solution to what is potentially a homework assignment, but this one is rather obviously not a homework assignment, and since you say you've already read up on joins and the penny still hasn't dropped, here ya go...
Code:
SELECT table1.*
, table2.*
, table3.*
, table4.*
FROM table1
INNER
JOIN table2
ON table2.id = table1.id
INNER
JOIN table3
ON table3.id = table1.id
INNER
JOIN table4
ON table4.id = table1.id
WHERE table1.id = '$record'
|

December 19th, 2012, 05:01 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 26 m 34 sec
Reputation Power: 0
|
|
|
I tried this, and Computer Says No
Is there an error in your syntax?
|

December 19th, 2012, 06:34 AM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
Quote: | Originally Posted by Marko2012 I tried this, and Computer Says No |
perhaps you would be so kind as to post the actual query that you ran to which your computer made this fascinating reply

|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|