How to form this SQL query?

There is a table:
1. shop_order (id, contact ID,state_id)
2. contact_data (id, contact ID, field, value)

The second table has the following form:
id | contact ID | field | value
1 | 25 | phone | 89167777777
2 | 25 | city | Moscow
3 | 26 | phone | 89164444444
4 | 26 | city | Moscow
5 | 27 | phone | 89164443333
6 | 27 | city | Tver

How to download all orders (shop_order) and phone numbers of a contact to these orders (contact_data), which have shop_order.state_id='paid', and the city of Moscow?
March 19th 20 at 08:59
2 answers
March 19th 20 at 09:01
Solution
select t1.*, t2.value as phone from shop_order as t1
left join contact_data as t2 on t1.contact ID = t2.contact ID
where t2.field='phone' and t2.contact ID in (select contact ID from shop_order where t1.state_id='paid' and value='Moscow')
March 19th 20 at 09:03
SELECT * FROM shop_order 
INNER JOIN contact_data USING(contact ID)
WHERE shop_order.state_id='paid' AND contact_data.value='Moscow'
Phone number no here.. - Elias.Farrell commented on March 19th 20 at 09:06
@Elias.Farrell, ??? - Adolf.Legr commented on March 19th 20 at 09:09
@Adolf.Legr, in your version of the query I don't get the phone number from the table contact_data - Elias.Farrell commented on March 19th 20 at 09:12
@Elias.Farrell, ahh...

SELECT contact_data.value FROM shop_order 
INNER JOIN contact_data USING(contact ID)
WHERE shop_order.state_id='paid' AND contact_data.value='Moscow'
- Adolf.Legr commented on March 19th 20 at 09:15

Find more questions by tags MySQL