Selecting more than one mysql table (join?)

Associate
Joined
19 Jun 2006
Posts
162
Location
Swansea, Wales
I have two mysql tables. Both tables have three fields which have the same names... "version", "type" and "id".

I want to select the version and type columns from both tables if either table has an id = $id.

I used a join statement...

Code:
SELECT rtcp_sr_packets.uniqueid, rtcp_sr_packets.Version, rtcp_sr_packets.Type, rtcp_sdes_packets.uniqueid, rtcp_sdes_packets.Version, rtcp_sdes_packets.Type FROM `rtcp_sr_packets`, `rtcp_sdes_packets` WHERE rtcp_sr_packets.`Call-ID` = 'Call-ID:f6ea990c-5bfe-db11-892e-0014a411311e@robuntu';

Then i displayed each row of the result in php as normal but instead of showing the four different packets it should have, it just shows two packets and then the same two packets again.

Not sure where I'm going wrong with this one. A little help...! :confused:
 
I can't put the data in the same table because after the first three fields the data is different.

Table 1: id, ver, type, x, y, z
Table 2: id, ver, type, a, b, c

I want to create a list of all the entries in table 1 and 2 where id = $id, displaying the ver and the type.

Then, when I click on one of the items in the list I can query the specific table to get the rest of the fields.
 
Well the type field is unique to the table so i can just look at what type is returned to know which table i need to query further.

Two queries may be the way to go though.
 
Just so everyone knows, the problem was cracked with a good old UNION ALL statement :D

Thanks very much to Jaffa_Cake!
 
Back
Top Bottom