简体   繁体   中英

SQL query to fetch list of records in subquery

How to write query to fetch the record something like this,

I have two tables as mentioned below,

在此处输入图片说明

Now, i want to fetch record for 1 row - list of column dtls as below query

select a.ID AS ID, A.Row_NO as Row_NO, b.* as b from A a, B b

Please help me to fetch records based on my requirement.

Use LEFT JOIN or INNER JOIN (see links for documentation)

SELECT i.ID as ID, i.Row_NO as Row_NO, j.* AS j FROM A AS i 
LEFT JOIN B AS j 
ON i.Row_NO = j.Row_NO

btw this query would be easier readable if you don't use capital letters in your table structure

Try this

SELECT
   a.ID AS ID,
   a.Row_NO as Row_NO,
   b.ID AS bID,
   b.Col_No,
   b.Value 
FROM A a
INNER JOIN B b ON (b.Row_No = a.Row_No);

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