Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6180529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:51:30+00:00 2026-05-24T00:51:30+00:00

I had two queries – one that selects group_id by knowing the post_id ,

  • 0

I had two queries – one that selects group_id by knowing the post_id, and one that checks that user is in that group. I tried to optimize them – put them together, but it now throws an error…

SELECT COUNT(bio_community_group_members.id) AS count
FROM `bio_community_group_members`
JOIN `bio_community_posts`
    ON (`bio_community_posts`.`id` = `180`)
WHERE `bio_community_group_members`.`group_id` = 'bio_community_posts.group_id'
    AND `bio_community_posts`.`user_id` = '34'

It says:

Unknown column ‘180’ in ‘on clause’.

Problem: I have that 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 to retrieve status from bio_community_group_members if it exists. That count thing was just because I didn’t knew how to start to build my query. 🙁

Thanks in advice.

Edit:

Hmm… now it works….. but any idea how to optimize those two queries and get one that also selects status?

SELECT `group_id`
FROM `bio_community_posts`
WHERE `id` = 180

SELECT COUNT(id) AS count
FROM `bio_community_group_members`
WHERE `group_id` = 41
  AND `user_id` = '34'

Edit #2:

This is what I was looking for:

SELECT `bio_community_group_members`.`status`
FROM `bio_community_group_members`
JOIN `bio_community_posts` ON `bio_community_posts`.`group_id` = `bio_community_group_members`.`group_id`
WHERE `bio_community_group_members`.`group_id` = 41
  AND `bio_community_group_members`.`user_id` = '34'
  AND `bio_community_posts`.`id` = '180'
GROUP BY `bio_community_group_members`.`status`

Thanks! 🙂

Edit #3:

I guess that i need something like this…

SELECT `bio_community_group_members`.`status`
FROM `bio_community_group_members`
JOIN `bio_community_posts` ON `bio_community_posts`.`group_id` = `bio_community_group_members.group_id`
WHERE `bio_community_posts`.`id` = '180'
AND `bio_community_posts`.`user_id` = '34'

But:

[Err] 1054 – Unknown column ‘bio_community_group_members.group_id’ in ‘on clause’.

Edit #4:

Just found a bug in the query. Here is the ultimate solution:

SELECT `bio_community_group_members`.`status`
FROM `bio_community_group_members`
JOIN `bio_community_posts` ON `bio_community_posts`.`group_id` = `bio_community_group_members`.`group_id`
WHERE `bio_community_posts`.`id` = '180'
AND `bio_community_posts`.`user_id` = '34'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:51:30+00:00Added an answer on May 24, 2026 at 12:51 am

    Remove the back-quotes(?) on 180, I think you meant ‘180’? Also remove single-quotes around the other column name, like this:

    SELECT COUNT(bio_community_group_members.id) AS count
    FROM `bio_community_group_members`
    JOIN `bio_community_posts`
        ON (`bio_community_posts`.`id` = '180') -- Replaced back- with single-quotes.
    WHERE `bio_community_group_members`.`group_id` = `bio_community_posts.group_id` -- Replaced single- with back-quotes.
        AND `bio_community_posts`.`user_id` = '34'
    

    Edit after OP edit:

    I’m not exactly sure what kind of optimization you are looking for, but I’m guessing it’s something like this?

    SELECT COUNT(id) AS count, status
    FROM `bio_community_group_members`
    JOIN `bio_community_posts` ON `bio_community_posts`.`group_id` = `bio_community_group_members`.`group_id`
    WHERE `bio_community_group_members`.`group_id` = 41
      AND `bio_community_group_members`.`user_id` = '34'
      AND `bio_community_posts`.`id` = '180'
    GROUP BY `bio_community_group_members`.`status`
    

    Edit after comments:
    Fixed your edit 3:

    SELECT `bio_community_group_members`.`status`
    FROM `bio_community_group_members`
    JOIN `bio_community_posts` ON `bio_community_posts`.`group_id` = `bio_community_group_members`.`group_id`
    WHERE `bio_community_posts`.`id` = '180'
    AND `bio_community_posts`.`user_id` = '34'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had two separate interfaces, one 'MultiLingual' for choosing language of text to return,
That is, if I had two or more sets, and I wanted to return
I have an application that queries and updates two databases at the same time
How would you go about proving that two queries are functionally equivalent, eg they
I have two queries that are basically the same: OLD TRANSACTIONS QUERY SELECT t.payment_method,
If you had two snippets: (global-set-key \C-d delete-char) and (define-key global-map \C-d delete-char) Is
Originally I had two tables in my DB, [Property] and [Employee]. Each employee can
So I just started my first rails project yesterday. I had two many-to-many (has_and_belongs_to_many)
This is a link to a question I had asked two days back, How
Has anyone had any success running two different web servers -- such as Apache

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.