I’m relatively new to SQL so the following might be a simple question. I’ve been trying to write a query that only returns names that have two specific types of addresses associated with them. There is a name table and an address table. It’s in a MYSQL server.
customer
| id | name |
| 1 | john smith |
| 2 | bob vance |
| 3 | jane doe |
| 4 | doug smith |
address
| id | type | street | state | name_id |
| 1 | home | 123 main street | NJ | 3 |
| 2 | business | 100 south lane | NY | 3 |
| 3 | home | 75 boardwalk way | CT | 1 |
| 4 | home | 3 cherry lane | NY | 2 |
| 5 | home | 15 south way | NY | 4 |
| 6 | business | 90 west end | NY | 4 |
I would like to return names who have both a home and business address, demonstrated in the results below.
| name | type | street | state |
| jane doe | home | 123 main street | NJ |
| jane doe | business | 100 south lane | NY |
|doug smith| home | 15 south way | NY |
|doug smith| business | 90 west end | NY |
I am able to join the tables together, however I am having difficulty filtering in this manner. Any assistance would be greatly appreciated!
http://sqlfiddle.com/#!2/be63a/1