首页 > 解决方案 > 查询以从子表中获取不同的数据

问题描述

请提供查询以获取我的结果。

我有两个表如下。

price_band

id  club_id  name  price
1      6     test   2.3
2      6     test1  3.3

price_band_seat

id  price_band_id  row seat  block_id
1     1              a   1      1
2     1              a   2      1
3     1              b   1      2
4     2              b   2      2

and result that i want 

Price  block_id  price_band_id  row 
2.3       1            1         a
2.3       2            1         b
3.3       2            2         b

查询排除 block_id 和 price_band_id 相同的原始数据。在哪里线索你必须采取 club_id=6

标签: mysql

解决方案


请试试这个。

SELECT
  DISTINCT 
  A.Price,B.block_id,B.price_band_id,B.row 
FROM 
    price_band A
INNER JOIN price_band_seat B 
ON A.id = B.price_band_id
WHERE A.club_id = 6

推荐阅读