Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mysql Query.. how to get a difference in 2 results??

 
luis Fernandez
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I am trying to make a query:

I have one query where i get:
1
2
3
4

I have another query where i get:
2
3

I want a final query just to get:
1
4

is there some sintaxis to get these results?

Thanks in advance!
 
Paul Clapham
Sheriff
Posts: 21129
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't a general-purpose thing for finding the difference between two query results. For all we know those queries were based on completely unrelated tables. However if it's a more well-conditioned problem, for example the two queries are related in some way, then it's possible that there could be a variation of query #2 which returns the desired result.

Would you like to post the actual queries?
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like the previous poster said, giving your queries would be helpful. I didn't test the syntax, but in sybase a correlated subquery would return anything from one table that doesn't exist in another. You can also use 'not in' instead of 'not exists', however at least in the old days 'not exists' was faster due to its use of indexes.

select * from tablea a where not exists (select * from tableb b where a.key=b.key)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic