SELECT语句 - 忽略空白列 - 连接表

时间:2014-10-21 11:11:58

标签: mysql select null

我正在加入vTiger中的5个表格,以获取我需要的所有信息。但是,可以选择某些列为空。在这种情况下,我的SELECT语句失败,我无法检索其余的结果。如果列为空,如何通过添加“不存在”默认值来绕过此步骤?

$results = mysql_query("SELECT
    vtiger_potentialscf.potentialid, 
    vtiger_potential.potentialname, 
    vtiger_contactdetails.accountid,
    vtiger_contactdetails.salutation,
    vtiger_contactdetails.firstname,
    vtiger_contactdetails.lastname,
    vtiger_account.accountname,
    vtiger_crmentity.smownerid, 
    vtiger_crmentity.crmid, 
    vtiger_crmentity.label, 
    vtiger_users.id,
    vtiger_users.email1 

    FROM vtiger_potential 

    INNER JOIN vtiger_potentialscf ON vtiger_potentialscf.potentialid = vtiger_potential.potentialid 
    INNER JOIN vtiger_crmentity ON vtiger_potential.potentialid = vtiger_crmentity.crmid 
    INNER JOIN vtiger_users ON vtiger_crmentity.smownerid = vtiger_users.id 
    INNER JOIN vtiger_contactdetails ON vtiger_potential.related_to = vtiger_contactdetails.accountid
    INNER JOIN vtiger_account ON vtiger_account.accountid = vtiger_potential.related_to
    WHERE `cf_919` = DATE(NOW())");


while ($row = mysql_fetch_assoc($results)) {
    echo $row['email1'] . "<br />";
    echo $row['smownerid'] . "<br />";
    echo $row['potentialname'] . "<br />";
    echo $row['accountid'] . "<br />";
    echo $row['salutation'] . "<br />";
    echo $row['firstname'] . "<br />";
    echo $row['lastname'] . "<br />";
    echo $row['accountname'] . "<br />";

在这种情况下,我可以将vtiger_contactdetails清空。有关如何获取其余内容的任何建议,只是回应这些内容不可用?

1 个答案:

答案 0 :(得分:0)

您可以使用左连接。 看看http://www.w3schools.com/sql/sql_join_left.asp

感谢Abhik Chakraborty在评论中提供了更好的解释。