Danny620 Posted September 18, 2012 Share Posted September 18, 2012 Hi i have a mysql query that produces 3 pet ids however i only have 1 in db whats going on? SELECT pet.active, pet_id, activation_code, pet.user_id, pet_name, pet_type, status, DATE_FORMAT(pet.registration_date, '%M %d, %Y') AS rd FROM pet, users WHERE activation_code LIKE '%%' && pet_id LIKE '%%' && users.email LIKE '%%' ORDER BY pet.pet_id DESC LIMIT 700, 100 Edit Active Pet ID Activation Code User ID Pet Name Pet Type Status Registered Date Reset Delete Edit Not In Use 1017 B0MQ0V19 User ID Cat Safe At Home reset delete Edit Not In Use 1017 B0MQ0V19 User ID Cat Safe At Home reset delete Edit Not In Use 1016 112X2FBG User ID Cat Safe At Home reset delete Edit Not In Use 1016 112X2FBG User ID Cat Safe At Home reset delete Edit Not In Use 1016 112X2FBG User ID Cat Safe At Home reset delete Edit Not In Use 1015 HJFW7DB9 User ID Cat Safe At Home reset delete Edit Not In Use 1015 HJFW7DB9 User ID Cat Safe At Home reset delete Edit Not In Use 1015 HJFW7DB9 User ID Cat Safe At Home reset delete Edit Not In Use 1014 D9UCRRFC User ID Cat Safe At Home reset delete Edit Not In Use 1014 D9UCRRFC User ID Cat Safe At Home reset delete Edit Not In Use 1014 D9UCRRFC User ID Cat Safe At Home reset delete Edit Not In Use 1013 FPIZAVEB User ID Cat Safe At Home reset delete Edit Not In Use 1013 FPIZAVEB User ID Cat Safe At Home reset delete Edit Not In Use 1013 FPIZAVEB User ID Cat Safe At Home reset delete Edit Not In Use 1012 FVFAX4SF User ID Cat Safe At Home reset delete Edit Not In Use 1012 FVFAX4SF User ID Cat Safe At Home reset delete Edit Not In Use 1012 FVFAX4SF User ID Cat Safe At Home reset delete Edit Not In Use 1011 9XN6IKHL User ID Cat Safe At Home reset delete Edit Not In Use 1011 9XN6IKHL User ID Cat Safe At Home reset delete Edit Not In Use 1011 9XN6IKHL User ID Cat Safe At Home reset delete Edit Not In Use 1010 IOUTFI3X User ID Cat Safe At Home reset delete Edit Not In Use 1010 IOUTFI3X User ID Cat Safe At Home reset delete Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 18, 2012 Share Posted September 18, 2012 At first glance, I see you're joining two tables and haven't specified on what column they should be joined. You also clearly have more than one pet id in the table, I count 8. I'm guessing you have 8 pets and 2 users. Quote Link to comment Share on other sites More sharing options...
shlumph Posted September 18, 2012 Share Posted September 18, 2012 You probably want a left join: SELECT pet.active, pet_id, activation_code, pet.user_id, pet_name, pet_type, status, DATE_FORMAT(pet.registration_date, '%M %d, %Y') AS rd FROM pet LEFT JOIN users ON pet.user_id = users.user_id WHERE activation_code LIKE '%%' && pet_id LIKE '%%' && users.email LIKE '%%' ORDER BY pet.pet_id DESC LIMIT 700, 100 Quote Link to comment Share on other sites More sharing options...
fenway Posted September 18, 2012 Share Posted September 18, 2012 Why all of the LIKE %%? 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.