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
11 Months Ago
Last Updated
Related Article: CSV file uploading into a MySQL Database?
is a solved PHP discussion thread by maydhyam that has 12 replies, was last updated 1 year ago and has been tagged with the keywords: mysql, csv, import.
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
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
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86