0

I'd like to save the result of the following query in an sql variable and than subtract that variable from the main table city to get my desired result.

SELECT *
FROM
city b1,city b2
WHERE
b1.from_city = b2.to_city
and b1.to_city = b2.from_city 

Any help will be much appreciated.

5
  • 1
    Which column are you trying to subtract? You cannot subtract record sets... Commented Mar 27, 2012 at 7:07
  • this query gives me two columns and i'd like to subtract both these columns from my main table city Commented Mar 27, 2012 at 7:10
  • Perhaps some example data would help? Commented Mar 27, 2012 at 7:38
  • The nature of the problem and example data is provided at the following link: stackoverflow.com/questions/9869526/… Commented Mar 27, 2012 at 7:43
  • The problem had been solved using join, now i'm trying to solve it without using it Commented Mar 27, 2012 at 7:44

1 Answer 1

2

it seems like you want to remove(in output) the rows having destination in circular form ..

if I am getting right then you can use following query -

select * from city a 
where not exists 
(select 1 from city b where b.from_city=a.to_city and b.to_city = a.from_city
)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.