This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
luis Fernandez
Greenhorn
Posts: 16
  • 0
  • 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
Pie
Posts: 20160
23
MySQL Database
  • 0
  • 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
  • 0
  • 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)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic