Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select non exists 2

Status
Not open for further replies.

ashstampede

Programmer
Joined
Aug 30, 2004
Messages
104
Location
GB
I want to use a non exists to return rows from two columns then based on my results do more operations. how do i keep the results of this select since there can be many rows returned?
 
Save it into a view, which will update as new data is entered into the original table. Or do a Select Into statement which will create a new table for you.



Catadmin - MCDBA, MCSA
Remember, "Work" is a four letter word. And you know what your mother told you about using four letter words!
 
Waht you need isn;t clear to me. COuld you perhaps give us some data structure and examples of what you want returned and what operations you want performed onthe data? It is ientirely possible that you could do what you need in one set-based statement, but without fuirther information it is hard to say.

Questions about posting. See faq183-874
Click here to learn Ways to help with Tsunami Relief
 
ok i will try clear things up.

i am doing a select non exists subquery bwtween two tables
Code:
Select column1,column2 from table1
where Not EXISTS
   (Select column1,column2
    from table2)

so i want to get the data from the 2 columns in table1 that weren't found in table2 then.
Then i want to do further operations on table 1 manily another select and some deletes from one or more tables depending on what i get back
 
You could select the results into a temp table and then work on the contents.

Code:
Select column1,column2
into #TMP_TABLE
from table1
where Not EXISTS
   (Select column1,column2
    from table2)

-- do whatever else you need to do using the results stored in #TMP_TABLE

-- drop the table when you're finished with it
DROP TABLE #TMP_TABLE
 
I would use the query as a derived table in the other statements. Examples below:
Code:
Select a.column1, b.column2 from table2 a join
(Select column1,column2 from table1
where Not EXISTS
   (Select column1,column2
    from table2))b
on a.column1 = b.column1

Delete from table3
where column1 in (Select column1,column2 from table1
where Not EXISTS
   (Select column1,column2
    from table2))

Questions about posting. See faq183-874
Click here to learn Ways to help with Tsunami Relief
 
thank you thedrider and sqlsister, i will need to do some figuring but both your answer have pointed me to a solution that will work for me one way or the other.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top