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 7855317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:20:50+00:00 2026-06-02T20:20:50+00:00

I have a Query that works like a charm, but now I need to

  • 0

I have a Query that works like a charm, but now I need to filter it by a value that is currently in a GROUP_CONCAT created field. i have learned that I can use HAVING to filter but I can’t find the syntax to use as HAVING groupconcatname LIKE '%6%' will find 6, 16, 26 etc .. I need to have the statement search for specific values so it can find “8” within the groupconcat containing 1,5,8,18,30,58 and not find 8 AND 18 AND 58 because i used a LIKE ‘%%’.

My Query (works right now .. but finds too many results based on a partial match of %6%):

SELECT offers.*, s.short_name AS sponsorName, s.logo AS sponsorLogo, GROUP_CONCAT( mn.title) titles, 
   GROUP_CONCAT( mo.`name`) metas, GROUP_CONCAT( om.meta_option) AS meta_ids
FROM offers 
INNER JOIN offer_metas as om ON om.offer_id = local_ld_offers.id 
INNER JOIN meta_options as mo ON om.meta_option = mo.id 
INNER JOIN meta_names as mn ON mo.category = mn.category AND mo.cat_seq = mn.seq 
LEFT JOIN sponsors AS s ON s.id=offers.sponsor 
GROUP BY offers.id 
HAVING meta_ids LIKE '%6%'
ORDER BY end_date ASC

I need to replace HAVING meta_ids LIKE '%6%' with something more akin to WHERE '6' IN meta_ids but when i try to replace the HAVING statement, with what seems like a reasonable attempt at a functioning WHERE, it ignores the fact that meta_ids is a valid variable/field to use in my clause and errors out.

Any recommendations?

Thanks,

Silver Tiger

UPDATE – Solved unless there is a more elegant way

Based on the recommendations from Thomas below I have updated the query and apparently I can search for as many individual values as I need by adding a line per option using the updated method as follows:

WHERE EXISTS( SELECT * FROM offer_metas AS om1 WHERE om1.meta_option = mo.id AND om1.meta_option = '23')
OR EXISTS( SELECT * FROM offer_metas AS om1 WHERE om1.meta_option = mo.id AND om1.meta_option = '16')
  • 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-06-02T20:20:51+00:00Added an answer on June 2, 2026 at 8:20 pm

    It isn’t clear exactly what is being asked here (some test inputs with expected outputs would help) but it doesn’t sound like you really need a Having clause. If you want to filter for values where say om.meta_option is “like” 8, then add a Where clause like so:

    Where Exists    (
                    Select 1
                    From meta_options As om1
                    Where om1.meta_option = mo.id
                        And om1.meta_option = Like '%8%'
                    )
    

    Of course, this return rows where there exists 8, 80, 18 and 181. If you are looking for a specific value equal to 8, then use:

    Where Exists    (
                    Select 1
                    From meta_options As om1
                    Where om1.meta_option = mo.id
                        And om1.meta_option = '8'
                    )
    

    If what you seek is a series of values, then you can do something like:

    Where Exists    (
                    Select 1
                    From meta_options As om1
                    Where om1.meta_option = mo.id
                        And om1.meta_option In('8','23')
                    )
    

    Remember that the purpose of the Having clause to apply filters after the grouping and the Where clause applies filters prior to the grouping. In this case, it sounds like the filtering should happen prior to the grouping and thus the Where clause should be used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this query that works perfectly: SELECT users.*, GROUP_CONCAT(categories.category_name) AS categories FROM
I have written a SQL query that works just fine, but am having a
I have the following that works like a charm. SELECT d.decisionName, c.firstname, c.lastname, o.name
I am using in C# MYsql .I have query that works if I run
I have this linq query that works well (although it may be written better,
I have the following query that works well. SELECT DISTINCT city,region1,region2 from static_geo_world where
I have a SQL query that I'm trying to debug. It works fine for
i have some problems with a Query seem IN dosen't work with Group_concat, that
Friends, I have a dynamic sql query that I would like to execute and
i have this script and it works, but not as i expected. I need

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.