![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
When I run SELECT * FROM dbo.table1 WHERE contr NOT IN (SELECT contr FROM dbo.table1 WHERE (type = 'T') GROUP BY contr) i get this: ID * * *Contr * Type 3 * * * 5555 * *W 5 * * * 7777 * *W 9 * * * 7777 * *W I think this is the correct result! |
|
Anyway there is also an alternative solution SELECT t1.* FROM dbo.table1 as t1 LEFT JOIN (SELECT contr FROM dbo.table1 WHERE * (type = 'T') GROUP BY contr) AS t2 ON t1.contr=t2.contr WHERE t2.contr IS NULL |
#12
| |||
| |||
|
|
On 5 Apr, 12:13, Henk van den Berg<hvandenb... (AT) xs4all (DOT) nl> wrote: If you SELECT contr FROM table1 WHERE (contr IN (SELECT contr FROM table1 WHERE (type<> 'T') GROUP BY contr) you will get the expected results. Not sure about this... if I SELECT contr FROM table1 WHERE (type<> 'T') i get also a number of "contr" where type='T', because of the different ID (that's the key). for example, in the results I have also 1250 because of the first line of the table... but that's not correct !!! Still, the simple version is preferable SELECT DISTINCT contr FROM table1 WHERE type<> 'T' again, wrong results... |
#13
| |||
| |||
|
|
hello. I need help with a query please... I've a table like this Id | Contr | Type the content of this table is like Id | Contract | Type 1 | 1250 | W 2 | 1250 | T 3 | 5555 | W 4 | 6666 | T 5 | 7777 | W 6 | 6666 | W 7 | 6666 | W 8 | 6666 | T 9 | 7777 | W 10 | 1250 | W 11 | 1250 | T 12 | 1250 | W 13 | 1250 | T 14 | 1250 | T the key is the ID I need to extract all the "Contr" where type is not "T" so i should have as result 3 | 5555 | W 5 | 7777 | W whenever i found a type "T", I have to exclude that number of "contr". I'm able to exclude all the records where type is not "T", but if I found type ="T", that contr goes into results because of the ID field... any idea of how I can do this ? thanks in advance p.s.sorry for my english, I'm Italian. I really hope you can understand me... |
#14
| |||
| |||
|
|
Are 'W' and "T" the only allowable types? If so: SELECT min(id),Contr,max(Type) FROM table GROUP BY Contr HAVING max(Type)<>'T' |
#15
| |||
| |||
|
|
hello. I need help with a query please... whenever i found a type "T", I have to exclude that number of "contr". I'm able to exclude all the records where type is not "T", but if I found type ="T", that contr goes into results because of the ID field... any idea of how I can do this ? |
#16
| |||
| |||
|
|
On 05-04-2011 13:17, Bob Barrows wrote: Are 'W' and "T" the only allowable types? If so: SELECT min(id),Contr,max(Type) FROM table GROUP BY Contr HAVING max(Type)<>'T' When I run that, the resultset contains 1250 which should be excluded since there's a row with 1250, T |
#17
| |||
| |||
|
|
sorry - I should have tested |
![]() |
| Thread Tools | |
| Display Modes | |
| |