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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:42:33+00:00 2026-05-22T23:42:33+00:00

I need to implement a search in a MySQL table. It stores data in

  • 0

I need to implement a search in a MySQL table. It stores data in different rows, so I have used the pivot functionality in MySQL to fetch the data.
It was working well when I need to search only one value (The table structure is below).

| id | lead_id | form_id | field_number | value   |
===================================================
| 1  |   12    |   12    |    2.3       | John    |
| 2  |   12    |   12    |    4.3       | Dublin  |
| 3  |   13    |   12    |    2.3       | Sam     |
| 4  |   13    |   12    |    4.3       | Cork    |
| 5  |   16    |   14    |    5         | 897894  |
| 16 |   16    |   16    |    7         | test    |
| 17 |   12    |   12    |    4.4       | Ireland |
| 18 |   12    |   12    |    7         | 8899899 |
| 19 |   13    |   12    |    4.4       | USA     |
| 20 |   13    |   12    |    7         | 0909902 |
--------------------------------------------------

The initial query I used to search is below. It was working well when I need to search only by ‘name’

SELECT lead_id, 
  MAX( IF( ROUND( `field_number` , 1 ) = '2.3', value, 0 ) ) AS "Name", 
  MAX( IF( ROUND( `field_number` , 1 ) = '4.3', value, 0 ) ) AS "City", 
  MAX( IF( ROUND( `field_number` , 1 ) = '4.4', value, 0 ) ) AS "State", 
  MAX( IF( ROUND( `field_number` , 1 ) = '7', value, 0 ) ) AS "SSnumber"
FROM details 
WHERE lead_id IN 
( 
  SELECT DISTINCT lead_id 
  FROM details 
  WHERE 
    (round(`field_number`,1) = '2.3' AND `value` LIKE '%s%') 
    AND form_id = 12 
)
GROUP BY `lead_id`

Now I need to implement a filter to search by city, state and pincode.
So I need to make changes on this query, but I am not getting it to work correctly.
I need to add an AND condition for the search to filter by city, state and pincode, Something like this.

SELECT lead_id, 
  MAX( IF( ROUND( `field_number` , 1 ) = '2.3', value, 0 ) ) AS "Name", 
  MAX( IF( ROUND( `field_number` , 1 ) = '4.3', value, 0 ) ) AS "City", 
  MAX( IF( ROUND( `field_number` , 1 ) = '4.4', value, 0 ) ) AS "State", 
  MAX( IF( ROUND( `field_number` , 1 ) = '7', value, 0 ) ) AS "SSnumber"
FROM details 
WHERE lead_id IN 
(
  SELECT DISTINCT lead_id 
  FROM details 
  WHERE 
  (
    (round(`field_number`,1) = '2.3' AND `value` LIKE '%s%') AND
    (round(`field_number`,1) = '4.3' AND `value` LIKE '%d%') AND
    (round(`field_number`,1) = '4.4' AND `value` LIKE '%r%') AND
  ) 
    AND form_id = 12 
)
GROUP BY `lead_id`

This is not working as data stored in different rows. Could you please suggest me a way to sort it.

  • 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-22T23:42:34+00:00Added an answer on May 22, 2026 at 11:42 pm

    I don’t fully understand conditions, but try to use a subquery. For example –

    SELECT * FROM (
      SELECT
        lead_id,
        MAX(IF(ROUND(field_number, 1) = '2.3', value, 0)) AS 'Name',
        MAX(IF(ROUND(field_number, 1) = '4.3', value, 0)) AS 'City',
        MAX(IF(ROUND(field_number, 1) = '4.4', value, 0)) AS 'State',
        MAX(IF(ROUND(field_number, 1) = '7', value, 0)) AS 'SSnumber'
      FROM details
        WHERE form_id = 12
        GROUP BY lead_id
      ) d
    WHERE 
      Name LIKE '%s%' AND City LIKE '%d%' AND State LIKE '%r%';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a application already working fine. I need to implement a quick search
I need to implement a search engine. So I have a dictionary which is
I have below combo box in mvvm-wpf application. I need to implement Text search
I can search multiple value with mysql. I need to implement SORT BY on
I need implement simple search in small content table: id, name, description, content. Results
I need to implement some search functionality within a Rails application. Most of the
I need to implement a data structure that supports insertion deletion and search in
I need to implement a feature that would allow users to filter table data
I need to implement some kind of metric space search in Postgres(*) (PL or
I need to implement a Query Object Pattern in Java for my customizable search

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.