We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,645 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

One to many relationship in mysql

Hi,
I have two tables and they have one to many relationship.The two tables are fares and fare preferences.Now in fares table there is a unique user id and username and the user id is related to multiple preferences.Now I want to make a query that displays the username once and its multiple preferences. I have used distinct but it is not working and I have also used group by which is of no use as it will display only one record. Can anyone help.
Thanks in advance

2
Contributors
3
Replies
2 Hours
Discussion Span
11 Months Ago
Last Updated
5
Views
saadi06
Junior Poster in Training
96 posts since Oct 2010
Reputation Points: 12
Solved Threads: 2
Skill Endorsements: 1

You will have to join them, returning the username in every row, and then use PHP, to display it the way you want. You cannot do this easily with just a query.

pritaeas
Posting Prodigy
Moderator
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86

Is there any way I can do in mysql query

saadi06
Junior Poster in Training
96 posts since Oct 2010
Reputation Points: 12
Solved Threads: 2
Skill Endorsements: 1

Give example data and what you want as output. You can look at GROUP_CONCAT though.

pritaeas
Posting Prodigy
Moderator
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0581 seconds using 2.64MB