Skip to content
Advertisement

Fetch data of two tables with/without match of Primary key and foreign key

I am using this query.

select * from  customers E JOIN `customer_p` D ON (E.ID = D.`P_ID`)

Here E.ID is primary key of customers table and p_ID is foreign key of customer_p This query fetches only those result in which primary key (ID) of customers table is present as foreign key (P__ID) of customer_p table and skips rest rows/data from customers table.

I want to fetch all date of customers table whether or not primary key (ID) do match with foreign key (P__ID). How can I do this?

Advertisement

Answer

Use LEFT JOIN instead of JOIN to get all rows in customers. see https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement