SQL多表查询,用于搜索的SQL语句,新手求大神帮忙,在线等 100分,
答案:2 悬赏:70 手机版
解决时间 2021-01-18 21:25
- 提问者网友:回忆在搜索
- 2021-01-18 15:16
SQL多表查询,用于搜索的SQL语句,新手求大神帮忙,在线等 100分,
最佳答案
- 五星知识达人网友:平生事
- 2021-01-18 15:56
不明白你要什么,多表联合查询的SQL语句? 还是自动生成表名不同字段相同的SQL语句的办法?追问就是做一个多表联合查询的SQL,用于搜索功能的!
表名字不同, 字段系统,条件相同追答我理解为 表结构相同,表名不同,对吧。你这样做联合查询有什么意义,联合查询是表示多表之间具有相关联的关系,你这样多表联合查询就查询不出结果。
你要是做多表查询,查看各表满足条件的记录的话就 UNIOn ALL 吧。
SELECt
`720_photo`.`id` AS `id`,
`720_photo`.`catid` AS `catid`,
`720_photo`.`title` AS `title`,
`720_photo`.`name` AS `name`,
`720_photo`.`places` AS `places`,
`720_photo`.`edittime` AS `edittime`,
`720_photo`.`thumb` AS `thumb`
FROM `720_photo`
WHERe
`720_photo`.`title` LIKE "%总经理%"
OR `720_photo`.`keywords` LIKE "%总经理%"
OR `720_photo`.`name` LIKE "%总经理%"
OR `720_photo`.`places` LIKE "%总经理%"
OR `720_photo`.`description` LIKE "%总经理%"
OR `720_photo`.`content` LIKE "%总经理%"
UNIOn ALL
SELECt
`620_photo`.`id` AS `id`,
`620_photo`.`catid` AS `catid`,
`620_photo`.`title` AS `title`,
`620_photo`.`name` AS `name`,
`620_photo`.`places` AS `places`,
`620_photo`.`edittime` AS `edittime`,
`620_photo`.`thumb` AS `thumb`
FROM `620_photo`
WHERe
`620_photo`.`title` LIKE "%总经理%"
OR `620_photo`.`keywords` LIKE "%总经理%"
OR `620_photo`.`name` LIKE "%总经理%"
OR `620_photo`.`places` LIKE "%总经理%"
OR `620_photo`.`description` LIKE "%总经理%"
OR `620_photo`.`content` LIKE "%总经理%"
如上,有多少个就UNIOn ALL 多少个。
把所有表中符合条件的都能查询出来
表名字不同, 字段系统,条件相同追答我理解为 表结构相同,表名不同,对吧。你这样做联合查询有什么意义,联合查询是表示多表之间具有相关联的关系,你这样多表联合查询就查询不出结果。
你要是做多表查询,查看各表满足条件的记录的话就 UNIOn ALL 吧。
SELECt
`720_photo`.`id` AS `id`,
`720_photo`.`catid` AS `catid`,
`720_photo`.`title` AS `title`,
`720_photo`.`name` AS `name`,
`720_photo`.`places` AS `places`,
`720_photo`.`edittime` AS `edittime`,
`720_photo`.`thumb` AS `thumb`
FROM `720_photo`
WHERe
`720_photo`.`title` LIKE "%总经理%"
OR `720_photo`.`keywords` LIKE "%总经理%"
OR `720_photo`.`name` LIKE "%总经理%"
OR `720_photo`.`places` LIKE "%总经理%"
OR `720_photo`.`description` LIKE "%总经理%"
OR `720_photo`.`content` LIKE "%总经理%"
UNIOn ALL
SELECt
`620_photo`.`id` AS `id`,
`620_photo`.`catid` AS `catid`,
`620_photo`.`title` AS `title`,
`620_photo`.`name` AS `name`,
`620_photo`.`places` AS `places`,
`620_photo`.`edittime` AS `edittime`,
`620_photo`.`thumb` AS `thumb`
FROM `620_photo`
WHERe
`620_photo`.`title` LIKE "%总经理%"
OR `620_photo`.`keywords` LIKE "%总经理%"
OR `620_photo`.`name` LIKE "%总经理%"
OR `620_photo`.`places` LIKE "%总经理%"
OR `620_photo`.`description` LIKE "%总经理%"
OR `620_photo`.`content` LIKE "%总经理%"
如上,有多少个就UNIOn ALL 多少个。
把所有表中符合条件的都能查询出来
全部回答
- 1楼网友:走死在岁月里
- 2021-01-18 16:54
F1单元格的公式直接复制到F16。sql文生成了。你想生成另外一个。直接黄色部分表名变更一下就出来了。然后复制F列内容。sql就出来了。
追问不懂,能给我写一个么追答看看能懂不。有问题留言 应该很容易解决你的问题追问就是做一个多表联合查询的SQL,用于搜索功能的!
表名字不同, 字段相同,条件相同!
这么连起来是不对的追答哦 你想都连接起来。结果显示一起??
Select XXXX From XXXX WHERe XXXX
Union
Select XXXX From XXXX WHERe XXXX
Union
Select XXXX From XXXX WHERe XXXX
Union
Select XXXX From XXXX WHERe XXXX
。。。。
选择字段前面不要加[表名.]
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯