?
Solved

mySQL results

Posted on 2011-09-11
4
Medium Priority
?
271 Views
Last Modified: 2012-05-12
Lets say you have the following table structure below

Location Table
id  | property_id | location_type
1   | 1           | 1
2   | 1           | 2
3   | 2           | 1
4   | 3           | 2
5   | 4           | 1
6   | 4           | 2

Amenities Table
id  | property_id | amenity_type
1   | 1           | 1
2   | 1           | 3
3   | 2           | 2
4   | 3           | 4
5   | 4           | 1
6   | 4           | 3


Is it possible to do something with the following tables

Select distinct property_id but the results would be like this


property_id | amenity_type
1           | 1,3,2
2           | 3,2,3
3           | 2,1,5

0
Comment
Question by:stargateatlantis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 36519254
not sure how you can come from your input data to the final data, but you surely want to use GROUP_CONCAT function ...
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html
0
 

Author Comment

by:stargateatlantis
ID: 36519270
Can you show me a working SQL statement with that sample data
0
 
LVL 60

Assisted Solution

by:Kevin Cross
Kevin Cross earned 1000 total points
ID: 36519395
I agree with a3, the final result is not valid for the sample you gave us. Anyway, using the Amenities table as the example (i.e., you can do the same thing with Locations).

SELECT property_id
     , GROUP_CONCAT(amenity_type) AS amenity_type
FROM Amenities 
GROUP BY property_id 
;

Open in new window


The manual reference by a3 already gives you more details.

P.S. please credit a3, I am just helping with the code example.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question