aspose file tools
The moose likes JDBC and the fly likes Mysql Query.. how to get a difference in 2 results?? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Mysql Query.. how to get a difference in 2 results??" Watch "Mysql Query.. how to get a difference in 2 results??" New topic
Author

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

luis Fernandez
Greenhorn

Joined: May 29, 2008
Posts: 16
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
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

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

Joined: Jun 26, 2002
Posts: 852
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)


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Mysql Query.. how to get a difference in 2 results??
 
Similar Threads
A Tricky Stored Procedure
mysql intersect
Regarding apply JOIN by using JPQL.
How to implement Tag Cloud Feature
Searching and matching keyword