需要多行具有相同值的IN OPERATOR

时间:2015-07-14 06:15:35

标签: sql

假设order_id 464646474648来自同一客户。

SELECT customer_id FROM orders WHERE order_id IN (4646, 4647, 4648)

结果:

customer_id
2589
2589
2589

每位客户都有gcm_registration_token

SELECT gcm_registration_token FROM customer_details WHERE customer_id IN (2589, 2589, 2589)

结果:

gcm_registration_token
dyB_PhRHddU:APA91bGAbuxAIlHUmH2XYK0pWM3ON37O_mTF7g...

我希望第二个查询返回具有相同gcm_registration_token的3行。

预期结果:

gcm_registration_token
dyB_PhRHddU:APA91bGAbuxAIlHUmH2XYK0pWM3ON37O_mTF7g...
dyB_PhRHddU:APA91bGAbuxAIlHUmH2XYK0pWM3ON37O_mTF7g...
dyB_PhRHddU:APA91bGAbuxAIlHUmH2XYK0pWM3ON37O_mTF7g...

解决方法是触发每个值的查询。但是,单一查询是否可行。

4 个答案:

答案 0 :(得分:3)

像这样使用JOIN

SELECT c.gcm_registration_token 
FROM orders o
JOIN customer_details c ON c.customer_id = o.customer_id
WHERE o.order_id IN (4646, 4647, 4648)

答案 1 :(得分:1)

您可以在以下内容中使用parseInt

SELECT gcm_registration_token 
FROM orders o
INNER JOIN customer_details d ON o.customer_id = d.customer_id
WHERE order_id IN (4646, 4647, 4648)

答案 2 :(得分:1)

使用INNER JOIN

SELECT `gcm_registration_token`
FROM `orders` o
INNER JOIN `customer_details` c ON `o`.`customer_id` = `c`.`customer_id`
WHERE `o`.`order_id` IN (4646, 4647, 4648)

答案 3 :(得分:0)

authorsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

此查询会混合客户明细表和订单表,并返回与左表中的where子句匹配的所有值