Foreba
Foreba

Reputation: 410

MySQL JOIN to fetch one result in one table and many in another

I have one table linked to another one (One-To-many (1:N) relationship). I'm trying to fetch the results from both tables with JOIN in MySQL, like so:

SELECT * 
FROM parent_table 
JOIN child_table 
ON (parent_table_id = child_table_id) 
WHERE parent_table_id = ?

Problem is that I can see the results from the parent table and only one result from the child table. How can I do to get one result from the parent table and all results from the child?

Upvotes: 0

Views: 57

Answers (1)

uvais
uvais

Reputation: 416

i think you need to try like this,,try this

SELECT * 
FROM parent_table 
RIGHT OUTER JOIN child_table 
ON (parent_table_id = child_table_id) 
WHERE parent_table_id = ?

Upvotes: 2

Related Questions