Given the customer table and loan table, I wish to find the customers who have not taken a loan. The schema definition is as follows:
mysql> select * from 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 * from 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, I tried the query : select customer_name from customer except select customer_name from borrower;
But I get the error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select customer_name from borrower' at line 1
I tried difference
also but the same kind of error pops out. But union
works well.
mysql> select customer_name from customer union select customer_name from 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 where I might be wrong?
Can you try:
so you select customer_name from customer that haven't take loan.
I haven't check but maybe is easier way.