如果字段不匹配(或具有NULL)值,您的查詢將不會返回結果。所以如果它是NULL,它不會這樣做。
您的查詢
SELECT content_type_clients.nid, content_type_clients.field_logo_display_value, files.filepath, node.title, node.created FROM content_type_clients, files, node WHERE content_type_clients.nid=node.nid AND files.fid=content_type_clients.field_client_logo_fid ORDER BY field_logo_display_value DESC, node.created ASC
實際上是寫的更現代(ANSI-92)
SELECT content_type_clients.nid, content_type_clients.field_logo_display_value, files.filepath, node.title, node.created
FROM content_type_clients
JOIN files ON files.fid=content_type_clients.field_client_logo_fid
JOIN node ON content_type_clients.nid=node.nid
ORDER BY field_logo_display_value DESC, node.created ASC
現在的舊方式(ANSI-89)如果你想查詢甚至返回結果當文件不匹配時,請使用LEFT OUTER JOIN替代:
SELECT content_type_clients.nid, content_type_clients.field_logo_display_value, files.filepath, node.title, node.created
FROM content_type_clients
JOIN node ON content_type_clients.nid=node.nid
LEFT OUTER JOIN files ON files.fid=content_type_clients.field_client_logo_fid
ORDER BY field_logo_display_value DESC, node.created ASC