MySQL多表多字段,关键字查询
项目中小程序需要一个输入框查询多表多字段内容sql如下:DROP VIEW IF EXISTS search;CREATE VIEW search ASSELECT article_id AS id,article_title AS `value`,'article' AS search_type FROM articleUNION ALLSELECT common_id AS i...
·
项目中小程序需要一个输入框查询多表多字段内容
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('%','东风','%')
即可查询对应表的数据
更多推荐
已为社区贡献1条内容
所有评论(0)