![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a table t1 : time1 unique, qty Entries : (1, 10) (2, 20) (3,30) (32,20) I want to find out the time1 values where qty is the same. select a1.time1, a2.time1 from t1 a1, t1 a2 where a1.qty = a2.qty and a1.time1 <> a2.time1 -- and a1.time1 a2.time1 produces output : ------- 32 2 2 32 But I want just one line in the output. Uncommenting the clause achieves the effect but somehow it seems a contrived way of getting the desired result. Besides if unique key is on (date + time), it would make the task more difficult. I think a more logical way would help me write the query efficiently whether the unique key was on a single field or multiple fields. Please advise about a logical way of writing the query. |
#3
| |||
| |||
|
|
I have a table t1 : time1 unique, qty Entries : (1, 10) (2, 20) (3,30) (32,20) I want to find out the time1 values where qty is the same. select a1.time1, a2.time1 from t1 a1, t1 a2 where a1.qty = a2.qty and a1.time1 <> a2.time1 -- and a1.time1 a2.time1 produces output : ------- 32 2 2 32 But I want just one line in the output. Uncommenting the clause achieves the effect but somehow it seems a contrived way of getting the desired result. Besides if unique key is on (date + time), it would make the task more difficult. I think a more logical way would help me write the query efficiently whether the unique key was on a single field or multiple fields. Please advise about a logical way of writing the query. |
|
select a1.time1, a2.time1 from t1 a1, t1 a2 where a1.qty = a2.qty and a1.time1 > a2.time1 ; |
#4
| |||
| |||
|
#5
| |||
| |||
|
|
One more point which I have been curious about . Why doesn't 'distinct' work on composite fields? Table t1 : a1 number, a2 number. Entries : (1,11) (2,21), (2,22) (2,22) (2,23) (2,23) (3,33) (3, 33) select distinct(a1, a2) from t1 ... does not work. How do I write that query? |
#6
| |||
| |||
|
|
select distinct(a1, a2) from t1 ... does not work. How do I write that query? |
#7
| |||
| |||
|
|
One more point which I have been curious about . Why doesn't 'distinct' work on composite fields? Table t1 : a1 number, a2 number. Entries : (1,11) (2,21), (2,22) (2,22) (2,23) (2,23) (3,33) (3, 33) select distinct(a1, a2) from t1 ... does not work. How do I write that query? |
![]() |
| Thread Tools | |
| Display Modes | |
| |