This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Query Preparation 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 "Query Preparation" Watch "Query Preparation" New topic

Query Preparation

Sameer Kumar

Joined: Jul 09, 2008
Posts: 6
Hi All,

1 200 500
2 100 300
3 555 666
4 666 555

5 541 256
6 454 45454
7 5656 122

I have a table with the sample data mentioned above.
I need to find the records where there is a circular reference between coloumns A and B.
For ex: record 3 & 4 refers to each other.
3 555 666
4 666 555

Can any one help me out how we can prepare this query.


Regards,<br />Sameer Kumar
Christophe Verré

Joined: Nov 24, 2005
Posts: 14687

select A,B from tbl t1 where exists (select 'X' from tbl t2 where t2.a = t1.b and t2.b = t1.a) ? Not sure.

[My Blog]
All roads lead to JavaRanch
I agree. Here's the link:
subject: Query Preparation
Similar Threads
jsp table
Not able to apply decode function to my query
Display output table
the world's smallest number?
printing out all my instances...toString() method..