php - MySQL One to many, pulling only selected record from many table -



php - MySQL One to many, pulling only selected record from many table -

i quite new @ sql statements , have never been @ joins etc. having problem working out how following:

i have 2 tables, 1 called music, 1 called reviews. 2 tables link on field called uid - records in music unique, there may many reviews each music record.

reviews has field called thumbsup, set value 1 if user gives music thumbs up. otherwise, field zero. there may many thumbsup in reviews, 1 thumbsup, or no thumbsup.

i trying display list of records in music, , if there corresponding review record contains thumbsup value of 1 - 1 record in reviews - display icon on list page.

i have had around various similar questions nil quite comes up. have tried doctoring around similar kinds of joins, frankly how works beyond me. sorry beingness idiot.

by way of evidence have @ to the lowest degree had go, far have come based on post:

select m.*, r.thumbsup (select max(thumbsup) uid reviews grouping uid) maxthumbs inner bring together reviews r on maxthumbs.uid = reviews.uid inner bring together music m on music.uid = reviews.uid

needless doesn't work :(

if help me out here right query construction extremely grateful.

many thanks

ted.

select distinct m.* music m inner bring together reviews r on m.uid = r.uid r.thumbsup > 0

php mysql one-to-many

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -