467,202 Members | 1,114 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,202 developers. It's quick & easy.

Comparison of two rows in a table using SQL ?

Hi,

Can anybody tell me how to compare two rows in a single tablle using SQL ?
Jun 20 '07 #1
  • viewed: 5797
Share:
3 Replies
Hi,

Can anybody tell me how to compare two rows in a single tablle using SQL ?
Try Self joins

eg: Select * from Table1 A, Table1 B
where (conditions )
Jun 22 '07 #2
Hi ,

Below is a sample data of the table.

IBPSUB IBPQTN CLIENT_INFORMATION CLASS ASSESTS
18783 1 Echo Test 1 - Client A 730 100000
18783 2 Echo Test 1 - Client A 730 120000
18784 1 Echo Test 1 - Client B 853 130000
18785 1 Echo Test 1 - Client C 853 100000
18785 81 Echo Test 1 - Client C 854 100000


Primary keys : IBPSUB and IBPQTN

My problem is : Whenever a Record having a particular IBPSUB has a IBPQTN number = 80 + IBPQTN , then I will have display the only record having greater IBPQTN value ..


My expected output from above table should be :

IBPSUB IBPQTN CLIENT_INFORMATION CLASS ASSESTS
18783 1 Echo Test 1 - Client A 730 100000
18783 2 Echo Test 1 - Client A 730 120000
18784 1 Echo Test 1 - Client B 853 130000
18785 81 Echo Test 1 - Client C 854 100000

IBPSUB 18785 has IBPQTN #1 and 81 ... since this IBPSUB had 1 and 81 in problem so the result should display only 81 not 1.

That's my problem ..

Please help me

Thanks
Jun 23 '07 #3
What you need is a query with correlated subquery using Max:

Select *
from table1 a
where IBPQTN =
(select max(IBPQTN)
from table1 b
where a.IBPSUB = b.IBPSUB)
Jun 27 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

133 posts views Thread by jonathan | last post: by
11 posts views Thread by csomberg@dwr.com | last post: by
reply views Thread by Tim Brooks | last post: by
1 post views Thread by Thats Me | last post: by
5 posts views Thread by Tara via AccessMonster.com | last post: by
7 posts views Thread by matt@mailinator.com | last post: by
13 posts views Thread by SQL Learner | last post: by
Eep≤
1 post views Thread by Eep≤ | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.