【发布时间】:2021-11-05 20:24:55
【问题描述】:
我有一个我认为非常独特的用例。我希望能够在数据库上运行单个 SELECT 语句,从四个表中获取一列。我需要在每个不同的表上运行 where 子句,其中我有一个跨每个表的主子句,我无法 JOIN 因为每列中的数据长度不同,我不想要有重复的项目。
下面有一个 Select 语句的示例。我也理解这是否不可能。
SELECT s.service_id, u.id AS "user_id", h.mac_address, l.id AS "location_id" FROM services s
LEFT JOIN db.av_product ap ON s.product_id = ap.id
WHERE s.customer_code LIKE 'test_customer'
AND u.customer_code LIKE 'test_customer'
AND h.customer_code LIKE 'test_customer'
AND l.customer_code LIKE 'test_customer'
AND s.parent_id IS NULL
AND s.active=0
AND ap.sku NOT REGEXP 'fakeregex'
AND l.active = "1"
AND h.hardware_id NOT IN ('44','45')
AND (u.support_user != 1 OR u.support_user IS NULL);
TIA!
【问题讨论】: