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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:44:59+00:00 2026-05-24T21:44:59+00:00

So I have two seperate tables. In the first table, there are a bunch

  • 0

So I have two seperate tables. In the first table, there are a bunch of ad groups which have an id. In the second table are a bunch of ads which have a column which contains the ad_group id for each ad. The ad_group_id is merely the id for the ad group from the ad group table. Therefore, I’m trying to select all ads which have an ad_group_id of 103, 104,105,107,117117,and 120.

So I tried the following query.

SELECT * FROM ads WHERE ad_group_id LIKE '%103%' OR ad_group_id LIKE '%104%'
OR ad_group_id LIKE '%105%' OR ad_group_id LIKE '%107%' OR ad_group_id LIKE '%117%' OR ad_group_id LIKE '%118%' OR ad_group_id LIKE '%120%';

So did the previous query work? YES

Was my query efficient? NO!

I am wondering how I can run the previous MySQL query in a more efficient manner.

EDIT:

AD GROUP - table 1
id    name
100   Tony
100   David
103   James
104   Ann
105   Jon
150   Sara

AD - table 2
keyword   ad_group_id
that        103
one         100
is          105
special     104
no          100
please      103

So I should end up with:

that        103
is          105
special     104
please      103

Hope that makes sense.

EDIT 2:

The following code gives the same result and is shorter, but I can’t imagine doing this when there is more values I need to select.

SELECT * FROM ads WHERE ad_group_id IN (103,104,105,107,117,118,120);
  • 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-24T21:45:00+00:00Added an answer on May 24, 2026 at 9:45 pm

    As I understand you store ad_group_id like id1,id2,id3 and so on.
    If yes this relation is many-to-many and more effectively to create additional table with
    2 columns ad_id,ad_group_id. But it depends on amount of your data.

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

Sidebar

Related Questions

I have two tables with hierarchyid fields, one of which is a staging table
Suppose you have two seperate ASP.NET Web Application projects that both need to use
I have two threads, one needs to poll a bunch of separate static resources
I'm guessing this isn't possible, but here goes. I have two tables, and I'm
I have a table full of data, where one column is full of different
I have a table called WorkItemNotes, and separate tables for Customers and Employees. I
I have a SalesOrder table and a separate Address table. The SalesOrder has two
I have a login.jsp page which contains a login form. Once logged in the
I have two tables: Messages: id message_text ..omitted.. Recipients id message_id recipient_id ..omitted.. I
I have two divs and two separate links that triggers slideDown and slideUp for

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.