Click here to Skip to main content
15,066,928 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Tried google but no success. I am using php with mysql. I have two tables- pm and pm_reply. I want to display all the records from these tables. I am using left join to combine tables. Problem is if pm has a row and pm_reply is empty, i am getting all the records from pm along with blank record that is i think from pm_reply.

Now plz tell me how to display all the records from pm and pm_reply without this blank record.

Here is my pm table:
pm_id int not null primary key autoincrement,
subject varchar(50) not null,
message text not null

And Here is pm_reply table:
pm_reply_id int not null primary key autoincrement, 
pm_id int not null,
resubject varchar(50) not null,
details text not null

And here is my query:
$sql=mysql_query("select pm.*,  pm_reply.* FROM pm LEFT JOIN pm_reply ON pm.pm_id=pm_reply.pm_id" );
Updated 13-Sep-14 7:40am
Mohibur Rashid 13-Sep-14 8:43am
don't join,
SELECT a.*, b.* FROM pm a, pm_reply b WHERE a.pm_id=b.pm_id
CHill60 13-Sep-14 13:52pm
That is a join!
Pankaj Mahor 13-Sep-14 9:29am
not working
ChauhanAjay 13-Sep-14 9:54am
You have mentioned that all the columns in your table are not null. So you will have to put a value in it. If you not entering any value then what are your storing in those columns.
Pankaj Mahor 13-Sep-14 10:22am
Both tables have data. Here i have only posted a question of my problem not my whole php code.

1 solution

Maybe this can be of help
mysql left join explanation[^]

Have you tried without the LEFT keyword?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900