![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, If I do something like "SELECT company_code FROM COMPANY_TYPE WHERE type_code = 1 AND type_code = 2" SQL Server returns 0 rows... |
#3
| |||
| |||
|
|
bobrivers (AT) pobox (DOT) com (Bob Rivers) wrote in message news:<aa669e9b.0307051943.806aa25 (AT) posting (DOT) google.com>... Hi, If I do something like "SELECT company_code FROM COMPANY_TYPE WHERE type_code = 1 AND type_code = 2" SQL Server returns 0 rows... That is correct, there are no rows where type_code = 1 and type_code = 2. I'll try to explain: What you want is all companies that are both clients and resellers. You can transform that to, All companies c where there exists a row in company_type where type_code = 1 and company = c and where there exists a row that has type_code = 2 and company c. I.e. select c.* from company c where exists ( select 1 from COMPANY_TYPE where company_code = c.company_code and company_type = 1 ) AND exists ( select 1 from COMPANY_TYPE where company_code = c.company_code and company_type = 2 ) Another solution would have been select c.* from company c, company_type ct where c.company_code = ct.company_code and ct.company_type = 1 intersect select c.* from company c, company_type ct where c.company_code = ct.company_code and ct.company_type = 2 In most cases I would go for the first solution HTH /Lennart |
![]() |
| Thread Tools | |
| Display Modes | |
| |