Solved

mySQL results

Posted on 2011-09-11
4
265 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
4 Comments
 
LVL 142

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 59

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
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…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now