php - mysql JOIN not working how I think it should -


can please explain why following query returning 5 copies of each row? have done wrong?:

( select user_id, act_id, act_date, act_score, users.posts_check,  'act'  'type' actswithscore join users user_id in ( 1, 5 ) ) union (  select user_voter, act_id, vote_date, vote_score, users.posts_check,  'vote'  type votes join users user_voter in ( 1, 5 ) ) limit 0 , 50 

i getting following result:

user_id act_id  act_date            act_score   posts_check         type 1       1       2014-02-05 05:25:25     null    2014-03-13 06:52:51  act 1       1       2014-02-05 05:25:25     null    0000-00-00 00:00:00  act 1       1       2014-02-05 05:25:25     null    0000-00-00 00:00:00  act 1       1       2014-02-05 05:25:25     null    0000-00-00 00:00:00  act 1       1       2014-02-05 05:25:25     null    0000-00-00 00:00:00  act 1       2       2014-02-05 05:28:16     1       2014-03-13 06:52:51  act 1       2       2014-02-05 05:28:16     1       0000-00-00 00:00:00  act 1       2       2014-02-05 05:28:16     1       0000-00-00 00:00:00  act 1       2       2014-02-05 05:28:16     1       0000-00-00 00:00:00  act 1       2       2014-02-05 05:28:16     1       0000-00-00 00:00:00  act 

rows 0 , 5 correct not sure why duplicating?

you forgot join tables. should be

( select user_id, act_id, act_date, act_score, users.posts_check,  'act'  'type' actswithscore join users on actswithscore.user_id=users.user_id user_id in ( 1, 5 ) ) union (  select user_voter, act_id, vote_date, vote_score, users.posts_check,  'vote'  type votes join users on votes.user_id=users.user_id user_voter in ( 1, 5 ) ) limit 0 , 50 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -