Suppose I have three tables: STORES
, STATES
, and STORES_STATES
.
STORES
contains records of individual storesSTATES
just contains a list of all 50 US statesSTORES_STATES
is a join table that contains pairs of stores and states to show which stores are available in which states
Consider the following tables (can't figure out how to format an ASCII table here):
What I need is a SELECT statement that will return each store in one column, and a list of states in another:
How do I combine the results of a subquery into a single column like this?
I would imagine it would be similar to this query:
SELECT
STORE_NAME,
(SELECT STATE_ABV FROM STORES_STATES WHERE STORES_STATES.STORE_ID = STORES.ID)
FROM STORES;
But this obviously fails since the subquery returns more than one result.