arprilia Posted December 20, 2006 Share Posted December 20, 2006 Need Help!!!i would like to display records for people that loves 'A' and loves 'B'...i'm having problem with this syntax...SELECT * FROM loves WHERE loveID = 'A' AND loveID = 'B'tried using the syntax below...SELECT lovesFROM kemahiranWHERE loveID IN ('A', 'B')..but it returns anyone who loves 'A' or 'B'......instead i wanna display people who love both 'A' & 'B'...please help....thanx in advance..... Quote Link to comment Share on other sites More sharing options...
artacus Posted December 20, 2006 Share Posted December 20, 2006 OR Quote Link to comment Share on other sites More sharing options...
arprilia Posted December 20, 2006 Author Share Posted December 20, 2006 i've already tried OR... but the record returns people who love A or B...i just wanna people who love both A and B...is it possible?? Quote Link to comment Share on other sites More sharing options...
artacus Posted December 20, 2006 Share Posted December 20, 2006 Oh, got ya. Well looking at your query, it should only select people who love BOTH A and B.I'm abit confused by your "SELECT loves FROM kemahiran" Used in this syntax your table name is kemahiran but I'm GUESSING that kemahiran is a user in the loves table?I can only venture an educated guess w/o knowing how your db is setup. I'm guessing you have a users table, a loves table with a 1 to many relationship between the two.So for user_id 134 you might have an entries in the loves table that look like so[code]id user_id love_code355 134 A356 134 B357 134 F[/code]Is that's a poor educated guess, then tell us what your table structure is like Quote Link to comment Share on other sites More sharing options...
arprilia Posted December 20, 2006 Author Share Posted December 20, 2006 [quote author=artacus link=topic=119339.msg488685#msg488685 date=1166596109]Oh, got ya. Well looking at your query, it should only select people who love BOTH A and B.I'm abit confused by your "SELECT loves FROM kemahiran" Used in this syntax your table name is kemahiran but I'm GUESSING that kemahiran is a user in the loves table?I can only venture an educated guess w/o knowing how your db is setup. I'm guessing you have a users table, a loves table with a 1 to many relationship between the two.So for user_id 134 you might have an entries in the loves table that look like so[code]id user_id love_code355 134 A356 134 B357 134 F[/code]Is that's a poor educated guess, then tell us what your table structure is like[/quote]you're right....based on your 'poor educated guess' ;) ...there are 2 tables; user n love. altering your tbl above (if i may)[code]id user_id love_code355 134 A356 134 B357 134 F358 135 A359 135 C360 136 B[/code]i want to have user_id that have love_code A and B...if i use OR it will return user_id 134, 135 and 136...instead i want only user_id 134... Quote Link to comment Share on other sites More sharing options...
artacus Posted December 20, 2006 Share Posted December 20, 2006 Ok, now we can get somewhere ;)[code]SELECT *FROM users JOIN loves AS l1 ON users.id = l1.user_id AND l1.love_code = 'A'JOIN loves AS l2 ON users.id = l2.user_id AND l2.love_code = 'B'GROUP BY users.id[/code] Quote Link to comment Share on other sites More sharing options...
arprilia Posted December 20, 2006 Author Share Posted December 20, 2006 It works perfectly.... :othanks a lot...... i'll let u know if bugs arise.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.