你好,
我在这里遇到了问题。我正在开发搜索选项。我可以搜索名字,姓氏,公司名称和车牌。我只想显示左侧,也是客户信息,我通过以下查询获得。但是,如果客户没有铭牌,则不会显示客户。有没有办法防止这种情况?
SELECT DISTINCT A.*
FROM adressen AS A
OUTER JOIN fahrzeuge AS F
ON F.fa_kunden_id = A.ad_id
WHERE CONCAT(coalesce(A.ad_name), coalesce(A.ad_vorname),coalesce(A.ad_firma), coalesce(F.fa_kennzeichen)) LIKE '%"+wndHauptfenster.textfield_suche.Text+"%'
我也尝试过使用IFNULL,但这会导致'无结果',即使对于有车的客户也是如此:
SELECT DISTINCT A.*
FROM adressen AS A
OUTER JOIN fahrzeuge AS F
ON F.fa_kunden_id = A.ad_id
WHERE CONCAT(coalesce(A.ad_name), coalesce(A.ad_vorname),coalesce(A.ad_firma), coalesce(ifnull(F.fa_kennzeichen, 'leer'))) LIKE '%"+wndHauptfenster.textfield_suche.Text+"%'
更新:尝试给定的解决方案后,根本找不到任何内容。
SELECT DISTINCT A.*
FROM adressen AS A
OUTER JOIN fahrzeuge AS F
ON F.fa_kunden_id = A.ad_id
WHERE CONCAT(coalesce(A.ad_name, ''), coalesce(A.ad_vorname, ''),coalesce(A.ad_firma, ''), coalesce(F.fa_kennzeichen, '')) LIKE '%"+wndHauptfenster.textfield_suche.Text+"%'
Adressen中的专栏:
ad_vorname
包含Max
ad_name
包含Mustermann
ad_firma
包含Testfirma Inc
fa_kennzeichen
什么都没有。查询正在搜索的行不存在。答案 0 :(得分:0)
怎么样:
SELECT DISTINCT A.*
FROM adressen AS A
OUTER JOIN fahrzeuge AS F
ON F.fa_kunden_id = A.ad_id
WHERE CONCAT(coalesce(A.ad_name,''), coalesce(A.ad_vorname,''),coalesce(A.ad_firma,''), coalesce(F.fa_kennzeichen,'')) LIKE '%"+wndHauptfenster.textfield_suche.Text+"%'
答案 1 :(得分:0)
OUTER JOIN是语法错误。应为LEFT OUTER JOIN,或缩写为LEFT JOIN。
SELECT DISTINCT A.*
FROM adressen AS A
LEFT OUTER JOIN fahrzeuge AS F
ON F.fa_kunden_id = A.ad_id
WHERE CONCAT(coalesce(A.ad_name, ''), coalesce(A.ad_vorname, ''),coalesce(A.ad_firma, ''), coalesce(F.fa_kennzeichen, '')) LIKE '%"+wndHauptfenster.textfield_suche.Text+"%'