hello

I've got two tables that I want to be connected(let's call the A and B), so I made a third table. In table A and B i got two primary keys a_id and b_id. Now I create the third table named AB. Inside that I create ab_id as primary and two foreign keys with the names a_id and b_id..... all is all good right now, working fine.

Now to the issue, what should I write in the code to get example ab_id 1 to show all it's information. And by all information I mean all the info that a_id and b_id have in their tables. You get what I'm looking for here?

Does this require some kind of JOIN?

hello

I've got two tables that I want to be connected(let's call the A and B), so I made a third table. In table A and B i got two primary keys a_id and b_id. Now I create the third table named AB. Inside that I create ab_id as primary and two foreign keys with the names a_id and b_id..... all is all good right now, working fine.

Now to the issue, what should I write in the code to get example ab_id 1 to show all it's information. And by all information I mean all the info that a_id and b_id have in their tables. You get what I'm looking for here?

Does this require some kind of JOIN?

SELECT a.id as a_id,
 a.something_else, 
b.id as b_id FROM a, b, c 
WHERE c.a_id = a.id AND c.b_id = b.id
AND c.id = '1'

by something_else I mean the name of any other column(s) that you want to be included in the result. So if you have column like 'model_name' then it will be a.model_name

You must use 'as a_id' and as 'b_id' because both tables have the same column name 'id', that' why you need to use alias 'as'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.