Home > database >  Combine multiple select querys
Combine multiple select querys

Time:09-30

I have a problem where I have to combine 4 selects into one query. First query's result is used in second query, seconds in third and so on. What is the optimal approach? Any suggestions are appreciated.

CodePudding user response:

Try to use sub query ( Query Under another Query )

CodePudding user response:

I am assuming that certain conditions make you write 4 select queries. You can put the static condition initially and get the data into the table variable or tmp table, from now this will be your source data. For each select query result add into a separate tmp table, make sure that the data is not duplicating on the 2nd, 3rd, and so on tmp tables, if it is delete the duplicates. The final result will be the union of all the tmp results.

  • Related