mysql - Problems with query optimization -
i had 2 queries - 1 selects group_id
knowing post_id
, , 1 checks user in group. tried optimize them - put them together, throws error...
select count(bio_community_group_members.id) count `bio_community_group_members` join `bio_community_posts` on (`bio_community_posts`.`id` = `180`) `bio_community_group_members`.`group_id` = 'bio_community_posts.group_id' , `bio_community_posts`.`user_id` = '34'
it says:
unknown column '180' in 'on clause'.
problem: have entry!
table structure:
bio_community_posts
:
id
,user_id
,group_id
,- other stuff;
bio_community_group_members
:
id
,user_id
,group_id
,status
,- other stuff;
i need retrieve status
bio_community_group_members
if exists. count
thing because didn't knew how start build query. :(
thanks in advice.
edit:
hmm... works..... idea how optimize 2 queries , 1 selects status
?
select `group_id` `bio_community_posts` `id` = 180 select count(id) count `bio_community_group_members` `group_id` = 41 , `user_id` = '34'
edit #2:
this looking for:
select `bio_community_group_members`.`status` `bio_community_group_members` join `bio_community_posts` on `bio_community_posts`.`group_id` = `bio_community_group_members`.`group_id` `bio_community_group_members`.`group_id` = 41 , `bio_community_group_members`.`user_id` = '34' , `bio_community_posts`.`id` = '180' group `bio_community_group_members`.`status`
thanks! :)
edit #3:
i guess need this...
select `bio_community_group_members`.`status` `bio_community_group_members` join `bio_community_posts` on `bio_community_posts`.`group_id` = `bio_community_group_members.group_id` `bio_community_posts`.`id` = '180' , `bio_community_posts`.`user_id` = '34'
but:
[err] 1054 - unknown column 'bio_community_group_members.group_id' in 'on clause'.
edit #4:
just found bug in query. here ultimate solution:
select `bio_community_group_members`.`status` `bio_community_group_members` join `bio_community_posts` on `bio_community_posts`.`group_id` = `bio_community_group_members`.`group_id` `bio_community_posts`.`id` = '180' , `bio_community_posts`.`user_id` = '34'
remove back-quotes(?) on 180, think meant '180'? remove single-quotes around other column name, this:
select count(bio_community_group_members.id) count `bio_community_group_members` join `bio_community_posts` on (`bio_community_posts`.`id` = '180') -- replaced back- single-quotes. `bio_community_group_members`.`group_id` = `bio_community_posts.group_id` -- replaced single- back-quotes. , `bio_community_posts`.`user_id` = '34'
edit after op edit:
i'm not sure kind of optimization looking for, i'm guessing it's this?
select count(id) count, status `bio_community_group_members` join `bio_community_posts` on `bio_community_posts`.`group_id` = `bio_community_group_members`.`group_id` `bio_community_group_members`.`group_id` = 41 , `bio_community_group_members`.`user_id` = '34' , `bio_community_posts`.`id` = '180' group `bio_community_group_members`.`status`
edit after comments: fixed edit 3:
select `bio_community_group_members`.`status` `bio_community_group_members` join `bio_community_posts` on `bio_community_posts`.`group_id` = `bio_community_group_members`.`group_id` `bio_community_posts`.`id` = '180' , `bio_community_posts`.`user_id` = '34'
Comments
Post a Comment