如何找到给定的值出现在mysql的哪些表中

时间:2015-11-03 06:38:23

标签: mysql sql

我有5张桌子。

给定折扣价值,我想查找折扣价值是出现在哪些表格及其对应的userids中。

例如:让我们说12% discount。我想检查12% exists在哪些表格中(例如,表格2,表格3)以及他们的userid

注意:折扣价值在给定表格中仅出现一次(唯一折扣)

有人可以帮助我:)

table1(userid,discount)  
table2(userid,discount)    
table3(userid,discount)    
table4(userid,discount)    
table5(userid,discount)

2 个答案:

答案 0 :(得分:0)

Select * from (select  userid,discount  from table1
union All
select  userid,discount  from table2
union All
select  userid,discount  from table3
union All
select  userid,discount  from table4
union All
select  userid,discount  from table5
 ) a where discount = 12

希望这个人能帮助你找到答案。

答案 1 :(得分:0)

尝试此查询: -

Select * from 
(
select  userid,discount  from table1
union
select  userid,discount  from table2
union
select  userid,discount  from table3
union
select  userid,discount  from table4
union
select  userid,discount  from table5
) 
dis where dis.discount = 12