简体   繁体   中英

sql - select multiple values from subquery

Is it possible to select multiple values from a subquery in SELECT block?

Selecting one value works fine like this:

SELECT
  a.id,
  (SELECT b.id FROM b WHERE b.a_id = a.id) AS b_id
FROM
  a

But if i also want to get the b.name and i change the query to this:

SELECT
  a.id,
  (SELECT b.id, b.name FROM b WHERE b.a_id = a.id)
FROM
  a

... it doesn't work anymore. One possibility would be to put the subquery to FROM block and take values from there but in my particular query that doesn't work so i would like to solve in SELECT block. Thank you!

This will help you

SELECT A.ID,
       B.ID,
       B.NAME
FROM   A INNER JOIN B ON B.A_ID=A.ID;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM