D
D
Dmitry Sergeev2011-12-14 20:21:10
MySQL
Dmitry Sergeev, 2011-12-14 20:21:10

mysql. How to merge two forms of normalization?

Let's say there are tables
1. main, contains information about companies
id | name | address

2. first normalization table, contains the brands the company works with (one company - many brands)
brend_id | firm_id

3. second normalization table, contains the cities where the company operates (one firm - many cities)
town_id | firm_id

Which query can retrieve all companies for a certain brand and a certain city? While the idea came to mind to make the third normalization table
firm_id | brand_id | town_id
but confuses a big overhead

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
edogs, 2011-12-14
@JetMaster

select * from company left join brands on company.id=brands.firm_id left join towns on company.id=towns.firm_id
where brands.brend_id in (desired brand or multiple) and towns.town_id in (desired city or multiple)
group by company.id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question