MySQL except clause doesnt work -
given customer table , loan table, wish find customers have not taken loan. schema definition follows:
mysql> select * customer; +---------------+-----------------+---------------+ | customer_name | customer_street | customer_city | +---------------+-----------------+---------------+ | adams | spring | pittsfield | | brooks | senator | brooklyn | | curry | north | rye | | glenn | sand hill | woodside | | green | walnut | stamford | | hayes | main | harrison | | johnson | alma | palo alto | | jones | main | harrison | | lindsay | park | pittsfield | | smith | north | rye | | turner | putnam | stamford | | williams | nassau | princeton | +---------------+-----------------+---------------+ 12 rows in set (0.00 sec) mysql> select * borrower; +---------------+---------+ | customer_name | loan_id | +---------------+---------+ | adams | l16 | | curry | l93 | | hayes | l15 | | jackson | l14 | | jones | l17 | | smith | l11 | | smith | l23 | | williams | l17 | | adams | l19 | | adams | l15 | | jones | l15 | | williams | l23 | +---------------+---------+ 12 rows in set (0.00 sec) now, tried query : select customer_name customer except select customer_name borrower;
but error:
error 1064 (42000): have error in sql syntax; check manual corresponds mysql server version right syntax use near 'select customer_name borrower' @ line 1 i tried difference same kind of error pops out. union works well.
mysql> select customer_name customer union select customer_name borrower; +---------------+ | customer_name | +---------------+ | adams | | brooks | | curry | | glenn | | green | | hayes | | johnson | | jones | | lindsay | | smith | | turner | | williams | | jackson | +---------------+ 13 rows in set (0.00 sec) any suggestions might wrong?
can try:
select customer_name customer customer_name not in (select customer_name borrower); so select customer_name customer haven't take loan.
i haven't check maybe easier way.
Comments
Post a Comment