Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

mySQL results

Posted on 2011-09-11
4
Medium Priority
?
273 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
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 …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

610 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