File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
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: 18113
    
    8

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
 
Don't get me started about those stupid light bulbs.
 
subject: Mysql Query.. how to get a difference in 2 results??
 
Similar Threads
A Tricky Stored Procedure
Regarding apply JOIN by using JPQL.
mysql intersect
How to implement Tag Cloud Feature
Searching and matching keyword