human
Schema:
phone (Name, Phone_ID, Memory_in_G, Carrier, Price)
market (Market_ID, District, Num_of_employees, Num_of_shops, Ranking)
phone_market (Market_ID, Phone_ID, Num_of_stock)
Please answer with SQL.
assistant
Sure, I understand.
human
Can you list all market ids and the names of the districts associated with them?
assistant
SELECT market_id , district FROM market;
human
Can you add to the table the phone ids from the table phone market that are associated with each market id?
assistant
SELECT t1.market_id , t1.district , t2.phone_id FROM market AS t1 JOIN phone_market AS t2 ON t1.market_id = t2.market_id;
human
Can you add to the table the name of the phones associated with each of the phone ids?
assistant
SELECT t2.market_id , t2.district , t1.phone_id , t3.name FROM phone_market AS T1 JOIN market AS T2 ON T1.Market_ID = T2.Market_ID JOIN phone AS T3 ON T1.Phone_ID = T3.Phone_ID;
human
Can you sort the table by phone id, but still retain all information within the table?
assistant
SELECT t2.market_id , t2.district , t1.phone_id , t3.name FROM phone_market AS T1 JOIN market AS T2 ON T1.Market_ID = T2.Market_ID JOIN phone AS T3 ON T1.Phone_ID = T3.Phone_ID ORDER by t1.phone_id ;