|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
How to compare 2 tables ??
Hi,
Need help with the structuring of the following query: I've got 2 tables nl :tableA, tableB I need to do a query to determine wat DISTINCT values of a column(cIdNo) in tableA is not present in column (bIdNo) in tableB. tableA contains Id numbers of people who still has to pay their bills, and tableB contains Id numbers of people who already paid. So I want a query to determine who still needs to pay. I've tried the following but doesn't work, not to sure if it's the right wayto do it: PHP Code:
PLEASE HELP !! Thanks in advance !!!
__________________
:P
|
|
#2
|
||||
|
||||
|
Sorry, been a long day... got it right eventually:
Here goes: PHP Code:
Any comments on the solution welcomed. ![]() |
|
#3
|
|||
|
|||
|
distinct is not a function. You dont need distinct when using in
Code:
SELECT distinct cIdNo as IdNumber FROM tableA WHERE cIdNo not in (Select bIdNo from tableB) |
|
#4
|
||||
|
||||
|
Thanks for your comments
I need to make use of distinct values in the first select because this is NOT a unique field, however doing a distinct select in the 2nd is irrelevant. The final query: PHP Code:
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > How to compare 2 tables ?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|