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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:46:29+00:00 2026-05-26T10:46:29+00:00

I am trying to write a query for a search. I have a meta

  • 0

I am trying to write a query for a search.

I have a meta table with columns:

ID | meta_key | meta_value

I want to pull a search like the following:

SELECT ID FROM meta_table WHERE meta_key = 'title' AND meta_value = 'searchword'

However, the complication is that I want to pull this from multiple sets of (multiple meta_keys and multiple meta_values) if that makes sense.
Here is one of the generated queries:

SELECT name_table_dan.ID FROM 
    (SELECT user_id as ID FROM wp_usermeta WHERE (meta_key = 'first_name' or meta_key = 'last_name') AND meta_value LIKE '%dan%') as name_table_dan 
INNER JOIN (SELECT user_id as ID FROM wp_usermeta WHERE (meta_key = 'first_name' or meta_key = 'last_name') AND meta_value LIKE '%newman%') as name_table_newman
    ON name_table_newman.ID=name_table_dan.ID 
    INNER JOIN (SELECT user_id as ID FROM wp_usermeta WHERE meta_key = 'user_industry' AND meta_value LIKE '%games%') as industry_table_games 
    ON industry_table_games.ID=name_table_newman.ID
    INNER JOIN (SELECT user_id as ID FROM wp_usermeta WHERE (meta_key = 'user_firm' or meta_key = 'company') AND meta_value LIKE '%incorp%') as company_table_incorp
    ON company_table_incorp.ID=industry_table_games.ID
    INNER JOIN (SELECT user_id as ID FROM wp_usermeta WHERE meta_key = 'user_location' AND meta_value LIKE '%denver%') as location_table_denver
    ON location_table_denver.ID=company_table_incorp.ID GROUP BY ID;

Sorry for the long query, but just trying to make my point.

The query works just fine the problem being that when some of these searches – namely, the select generated tables towards the beginning of the query – return large result sets, the query time slows down dramatically, and if I get a few large result sets then the query pretty much hangs the system to where I have to end the process manually.

I think the problem may lie with MySQL (I believe postgre does not have this problem). I looked around and discovered that mysql has problems with nested queries and joins.

I am asking what the best way to handle this would be? I ideally would like to avoid have multiple database calls as I feel this should be unnecessary, so this is not an answer I am looking for unless there is no alternative.

  • 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-26T10:46:29+00:00Added an answer on May 26, 2026 at 10:46 am
     SELECT name_table_dan.ID FROM wp_usermeta name_table_dan
         INNER JOIN wp_usermeta name_table_newman ON name_table_dan.ID = name_table_newman.ID
          ...
     WHERE 
       (name_table_dan.meta_key = 'first_name' OR name_table_dan.meta_key = 'last_name' AND name_table_dan.meta_value LIKE '%dan%')
       AND
       (name_table_newman.meta_key = 'first_name' OR name_table_newman.meta_key = 'last_name' AND name_table_dan.meta_value LIKE '%newman%')
     ...
    

    It is not the complete query translation of yours, but you get the idea. If MySQL is having problems with so many subqueries, try this one.

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

Sidebar

Related Questions

I'm trying to write a query for the find-as-you-type search bar. What I want
I'm trying to write a query I don't want to have Cartesian products on.
I'm trying to write a query for an advanced search page on my document
I'm trying to write an SQL query that would search within a CSV (or
I'm trying write a query to find records which don't have a matching record
I'm trying to write a query that will pull back the two most recent
I'm trying to write a query that extracts and transforms data from a table
I'm trying to write a query that updates rows in a table if a
I am trying to write a query that connects 3 tables. The first table
I'm trying to write myself a chrome extension, and I have the following lines

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.