SQL SHOW one more column name FROM operator in
I need to show columns from IN operator
My query is : SELECT prizes.type,prizes.name
FROM lottery_payment_prizes payment
JOIN lottery_prizes prizes ON
prizes.id = payment.prize_id
WHERE payment.payment_id IN
(( SELECT id FROM lottery_payments
WHERE lottery_id = (SELECT id FROM lotteries WHERE abbr = 'TR' AND group_id = '3' )))
Result is:
My question : How can show two columns from lottery_payments , lottery_payments returns only ID to IN operator
function.
I need to show column name "place" from lottery_开发者_开发知识库payemnts table. Thanks all.If you need to columns from lottery_payments
, you need to add a join to it:
SELECT payments.place, payments.id, prizes.type, prizes.name
FROM lottery_payment_prizes payment
JOIN lottery_prizes prizes ON
prizes.id = payment.prize_id
JOIN lottery_payments payments ON
payment.payment_id = payments.id
WHERE lottery_id = (SELECT id FROM lotteries WHERE abbr = 'TR' AND group_id = '3' )
Instead of using IN You should use join
SELECT prizes.type,prizes.name
FROM
lottery_payment_prizes payment
JOIN
lottery_prizes prizes ON prizes.id = payment.prize_id
JOIN lottery_payments lp ON payment.payment_id = lp.id
WHERE lp.lottery_id = (SELECT id FROM lotteries WHERE abbr = 'TR' AND group_id = '3' )))
精彩评论