I want to select * from several tables but eliminate duplicates without writing out all column names. There are approximately 30 columns from combined tables and I don't want to write each one out.
I know I could write out all column names, but I want to see if there is a way to do it with select *
SELECT
a.*
FROM "T1"."T2"."T3" a
LEFT JOIN "T1"."T2"."T4" b on b.id = a.id
LEFT JOIN "T1"."T2"."T5" c on c.id = a.id
LEFT JOIN "T1"."T2"."T6" d on d.id = a.id
WHERE a.org = '123' AND kind = 'abc'
Is there a way to group by a.id without having to write out every column name? There are 41 columns in the final table as is, and I am trying to only return distinct rows on id.
Not exactly group by
, but row_number()
:
SELECT a.*
FROM (SELECT a.*,
ROW_NUMBER() OVER (PARTITION BY a.id ORDER BY a.id) as seqnum
FROM "T1"."T2"."T3" a LEFT JOIN
"T1"."T2"."T4" b
ON b.id = a.id LEFT JOIN
"T1"."T2"."T5" c
ON c.id = a.id LEFT JOIN
"T1"."T2"."T6" d
ON d.id = a.id
WHERE a.org = '123' AND kind = 'abc'
) a
WHERE seqnum = 1;
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.