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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:38:06+00:00 2026-06-14T12:38:06+00:00

I have a column in one of my table where I store multiple ids

  • 0

I have a column in one of my table where I store multiple ids seperated by comma’s.
Is there a way in which I can use this column’s value in the “IN” clause of a query.

The column(city) has values like 6,7,8,16,21,2

I need to use as

select * from table where e_ID in (Select city from locations where e_Id=?)

I am satisfied with Crozin’s answer, but I am open to suggestions, views and options.

Feel free to share your views.

  • 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-14T12:38:07+00:00Added an answer on June 14, 2026 at 12:38 pm

    Building on the FIND_IN_SET() example from @Jeremy Smith, you can do it with a join so you don’t have to run a subquery.

    SELECT * FROM table t
    JOIN locations l ON FIND_IN_SET(t.e_ID, l.city) > 0
    WHERE l.e_ID = ?
    

    This is known to perform very poorly, since it has to do table-scans, evaluating the FIND_IN_SET() function for every combination of rows in table and locations. It cannot make use of an index, and there’s no way to improve it.

    I know you said you are trying to make the best of a bad database design, but you must understand just how drastically bad this is.

    Explanation: Suppose I were to ask you to look up everyone in a telephone book whose first, middle, or last initial is “J.” There’s no way the sorted order of the book helps in this case, since you have to scan every single page anyway.

    The LIKE solution given by @fthiella has a similar problem with regards to performance. It cannot be indexed.

    Also see my answer to Is storing a delimited list in a database column really that bad? for other pitfalls of this way of storing denormalized data.

    If you can create a supplementary table to store an index, you can map the locations to each entry in the city list:

    CREATE TABLE location2city (
     location INT,
     city INT,
     PRIMARY KEY (location, city)
    ); 
    

    Assuming you have a lookup table for all possible cities (not just those mentioned in the table) you can bear the inefficiency one time to produce the mapping:

    INSERT INTO location2city (location, city)
      SELECT l.e_ID, c.e_ID FROM cities c JOIN locations l
      ON FIND_IN_SET(c.e_ID, l.city) > 0;
    

    Now you can run a much more efficient query to find entries in your table:

    SELECT * FROM location2city l
    JOIN table t ON t.e_ID = l.city
    WHERE l.e_ID = ?;
    

    This can make use of an index. Now you just need to take care that any INSERT/UPDATE/DELETE of rows in locations also inserts the corresponding mapping rows in location2city.

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

Sidebar

Related Questions

I have a database table named 'student' in which there is one column named
i have a large mysql database table in which one column contains values ranging
Ok, so basically I need to select multiple IDs from one column, then use
I have a database table which stores products. Each product can have multiple colours.
by default I have one column in MySQL table to be NULL. I want
I have data table containing one column as FilePath. FilePath D:\New folder\link.txt D:\New folder\SharepointMigration(Work
I have a table with one column and four rows. Each tr has a
I have an HTML table with one column being email addresses; spambot issues aside,
I have two table. One table hold key column and xml column. Other table
I have a composite index on three column in one of my table. It

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.