Solved

mySQL results

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
subtr returning incorrect value 8 70
How do I figure out how much database is expected to grow? 15 80
Delete old Sharepoint backups 2 24
Error 438 6 18
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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…

730 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