如何在联接查询中检查过滤器的字段长度?

时间:2018-12-20 16:34:59

标签: mysql sql

当前我的查询如下:

SELECT * 
FROM suppliers s 
INNER JOIN supplier_addresses a 
ON s.id = a.supplier_id

supplier_addresses中有一个名为address的字段,我想用字符长度大于10的地址过滤上面的查询结果?

我尝试将where LEN(a.address) > 10添加到上面的查询中,但工作量很大。

2 个答案:

答案 0 :(得分:1)

您的查询应为:

SELECT * FROM suppliers s
INNER JOIN supplier_addresses a
ON (s.supplier_id = a.supplier_id)
WHERE LENGTH(a.address)>10;

答案 1 :(得分:1)

它应该像这样:

SELECT * 
FROM suppliers s 
INNER JOIN supplier_addresses a 
ON s.id = a.supplier_id
WHERE char_length(a.address) > 10