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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:01:22+00:00 2026-06-07T15:01:22+00:00

In my example query below, I am pulling all text that matches a keyword

  • 0

In my example query below, I am pulling all text that matches a keyword and splitting results by year-month. I prefer to search on ‘text’ – the concated version of all strings, instead of just against each field with a WHERE clause, but HAVING does not return any data:

SELECT 
date_format(created_date, '%Y-%m') as yr_mo,
count(id),
group_concat(coalesce(title,''),coalesce(story,'') SEPARATOR ' ') as text
from input_form
where dupe = 0 /*and story like '%flood%'*/
group by yr_mo
having text like '%flood%'
order by yr_mo

Below is what gets returns when I uncomment /** and story like ‘%flood%’ **/ and remove the HAVING clause:

yr_mo   count(id)   text
2011-04 2   Floods Roads in my  community one time proved to b...
2011-05 21  THE TRUSTED LADY.   It was during my usual visits ...
2011-06 22  HEAVY RAINFALL On our village we were affected wit...
2011-07 52  FEED THE CHILDREN PROGRAMME(1) The world food prog...
2011-08 29  I was saved and helped to prosperI am one of the v...
2011-09 15  FLOODS In the past three months the country have f...
2011-10 19  FLOODFlood is a very bad disaster at the same time...
2011-11 9   RESPONDING TO DISASASTERUNICEF landed over relief ...
2011-12 3   EARLY PREVENTION OF FLOODShaving sensed the likeli...
2012-01 44  HUNGER STRIKE             In Wataalamu village the...
2012-04 8   THE FALLEN BRIDGEThe Kambu bridge along the Mombas...
2012-05 7   Increasing earth's natural environment awarenessAf...
2012-06 4   A misery solvedRecently 10 people died in my commu...
2012-07 21  Lsot HopesWhen the Agricultural Farmers Society ca...

I’ve tried avoiding nulls with coalesce(story,”) but the result was the same.

EDIT #1: I found a longer and messier query to work, and provide me what I want:

SELECT 
date_format(created_date, '%Y-%m') as yr_mo,
count(if( ( story like '%hunger%' OR title like '%hunger%' ) and (story_location_city like '%nairobi%' OR story_location_neighborhood like '%nairobi%'),id,null)) as 'hunger',
count(if( ( story like '%poverty%' OR title like '%poverty%' ) and (story_location_city like '%nairobi%' OR story_location_neighborhood like '%nairobi%'),id,null)) as 'poverty',
count(if( ( story like '%school%' OR title like '%school%' ) and (story_location_city like '%nairobi%' OR story_location_neighborhood like '%nairobi%'),id,null)) as 'school',
count(id) as total
from input_form
where dupe = 0
group by yr_mo
order by yr_mo

If I must, I can search each field within an if() statement, and it will provide specific results. Is there no more efficient way to do this?

  • 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-07T15:01:25+00:00Added an answer on June 7, 2026 at 3:01 pm

    GROUP_CONCAT truncates its output to (by default) 1024 characters, so the HAVING clause requires that the string flood appear within the first 1024 characters of the concatenated text, whereas the WHERE clause merely requires that it appear somewhere in input_form.story.

    Even if it weren’t for the truncation, I think that GROUP_CONCAT + HAVING would not really be what you would want, since that would include all records for any month that had any matching record. For example, if April 2012 had twenty records, but only ten contained flood, then a GROUP_CONCAT + HAVING approach would (if not for the truncation) say that there were twenty matching records for April 2012, and would include text from all of them.

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

Sidebar

Related Questions

My current LINQ query and example XML are below. What I'd like to do
For example I have a mysql query that gets some data. Then runs another
For invoke search android example, every time query search result is received by onCreate().
For example I want the query below to match the description field with value
I was practising with an example that I was creating like the one below
I have a sql query that shows the year in one column and the
I have a sql query below, where dtMontno could start from any month and
Using MySQL and php how would I, in a single query, grab all results
How does maxresult property of hibernate query works? in the example below : Query
EDIT: Far simpler example. (Formerly titled: Oracle Column Injection) GOAL: Complete the query below

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.