I have 2 tables like this:
Table: Company
id| Name | Area
1 | Company A | New York
2 | Company B | New York
3 | Company C | Chicago
Table: Service
id| Type
1 | Service
1 | Delivery
2 | Hotel
2 | Restaurants
3 | Movers
I would like to get results just for New York like this (without chicago):
Name | Area | Type
Company A | New York| Service, Delivery
Company B | New York| Hotel, Restaurants
But i instead get this:
Name | Area | type
Company A | New York | Service
Company A | New York | Delivery
Company B | New York | Hotel
Company B | New York | Restaurants
I have tried using distinct and concat to solve my problems but the queries do not end, they instead time out after running for over 6 seconds. If i run a query to get the results i get right now, i get results in less then 1s.
Here are the queries i have tried so far:
select p1.Name,
GROUP_CONCAT(p2.Type) from company as p1, service as p2
GROUP BY p1.CompanyName
LIMIT 10;
Result: Time out
select DISTINCT company.Name from company
LEFT JOIN service
ON company.Number = service.Number AND service.Type LIKE '% York'
Limit 50;
Result: Never Ends (not even a time out)
select p1.Name, p2.type from company as p1, service as p2
where p1.id = p2.id
LIMIT 10;
Result: Shows really messed up results which are not possible like this:
Name | Type
Company A | Hotel
Company B | Delivery
Company B | Restaurants
The DB was originally Microsoft Access and i was getting such results in there, not being familiar with microsoft access i figured microsoft must be having problems and tried to get the query executed in mysql, but the same problems happening there... if i try to manually tally the data whats being shown does not tally at all and this has me really confused... can somebody please look into my queries and advise me what am i doing wrong? thx!