在 sqlite 中搜索时,我使用以下 SQL 搜索所有列一次:
Select id from table where '--' || IFNULL(name, ' ')
|| '--' || IFNULL(created, ' ') || '--' || IFNULL(desc, ' ')
|| '--' LIKE '%query%'
现在我需要搜索一个order
表和order details
表。他们看起来像这样
订单表
id
date
customer_id
订单详细信息
id
product_id
cost
orders_id
qty
在这种情况下如何搜索,我尝试使用连接:
Select o.id,o.customer_id from orders o where '--'
(Select * from customers where name like '%query%' and id=customer_id) '--'
|| (Select * from product where name like '%query%' and ID =
(Select product_id from order_details where id =odetails_id)) '--' LIKE '%query%'
编辑
我尝试了这个新查询,但在“或”处出现错误
SELECT o.id FROM orders o WHERE o.id in
((SELECT order_id FROM order_items WHERE order_items.service_id In
(SELECT id FROM services WHERE name like query))
OR o.id in
(SELECT order_id FROM order_items WHERE order_items.customer_id In
(SELECT id FROM customers WHERE name like query))
OR o.id in
(SELECT order_id FROM order_items WHERE order_items.cloth_id In
(SELECT id FROM cloths WHERE name like query) ))
我该如何解决