Solved

mySQL results

Posted on 2011-09-11
4
270 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 250 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 250 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

705 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