如何显示两个mysql表中的所有记录而不显示空白记录? [英] How to display all the records from two mysql tables without displaying blank record?
问题描述
尝试谷歌但没有成功。我正在使用php与mysql。我有两个表 - pm和pm_reply。我想显示这些表中的所有记录。我使用左连接来组合表。问题是如果pm有一行并且pm_reply为空,我从pm获取所有记录以及我认为来自pm_reply的空白记录。
现在请告诉我如何在没有此空白记录的情况下显示pm和pm_reply的所有记录。
这是我的下午表:
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
这里是pm_reply表:
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" );
推荐答案
sql = mysql_query( select pm。*,pm_reply。* FROM pm LEFT JOIN pm_reply ON pm.pm_id = pm_reply.pm_id);
sql=mysql_query("select pm.*, pm_reply.* FROM pm LEFT JOIN pm_reply ON pm.pm_id=pm_reply.pm_id" );
也许这可能会有所帮助
mysql左连接说明 [ ^ ]
您是否尝试过没有LEFT关键字?
Maybe this can be of help
mysql left join explanation[^]
Have you tried without the LEFT keyword?
这篇关于如何显示两个mysql表中的所有记录而不显示空白记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!