简体   繁体   中英

Using result of 1st select in union to query the second select

I would need help to make a query that will use the result of select 1 in a union as the criteria for query to.

example:

select * from table1 where name='xx'

union all

select * from table1 where Name=(select surname from table2 where surname='xx') -- (the name from first query)

This is what i got so far but everytime i query on it i only get one row

Select a.client, a.voucher_no from agltaxtrans a left outer join agltaxtrans b on a.voucher_no=b.voucher_no where a.voucher_no=b.voucher_no

union all

select client, voucher_no from agltaxtrans where voucher_no IN (select voucher_cor from a49bontaxtranshist b left outer join agltaxtrans a on a.voucher_no=b.voucher_cor where b.voucher_cor=a.voucher_no)

Solution is to create another column and name it something:

select name as name_original, name from tabel1

UNION all

select b.name as name_original, a.name as name from table1 a left outer join table2 b on a.city=b.city and a.name=b.surname

This way i can query on name_original and get the desired result

Thanks for the help

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