项目中小程序需要一个输入框查询多表多字段内容

sql如下:

DROP VIEW IF EXISTS search;
CREATE VIEW search AS
SELECT article_id AS id,article_title AS `value`,'article' AS search_type FROM article
UNION ALL
SELECT common_id AS id,common_totle AS `value`,'area' AS search_type FROM common_dict 
UNION ALL
SELECT yard_id AS id,yard_name AS `value`,'yard' AS search_type FROM yard
;

思路:将多表的id,名称拿出用UNION ALL关联做出一个视图

在这里插入图片描述
然后用关键字查询这个视图

SELECT * FROM search WHERE `value` LIKE CONCAT('%','东风','%')

即可查询对应表的数据

在这里插入图片描述

Logo

更多推荐