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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:08:52+00:00 2026-06-15T04:08:52+00:00

Possible Duplicate: Mysql WHERE problem with comma-separated list I have the next info in

  • 0

Possible Duplicate:
Mysql WHERE problem with comma-separated list

I have the next info in a table

name     categories
------   -----------
John      1,4
Jim       4,1
JAck      4,1

between other.

I want to select all the rows that pertain to category 4, but this statement..

SELECT name, categories
FROM `mytable`
WHERE 4 IN (categories)

returns only “Jim” and “Jack” but not “John”. What am I doing wrong?

Edit: Sadly I cant change the structure of the table. I need to use that comma-list style

  • 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-15T04:08:53+00:00Added an answer on June 15, 2026 at 4:08 am

    I am not sure why you are storing a comma separated list in a single column. But it you cannot change the table structure, you will want to use LIKE to compare the data:

    select name, categories
    from yourtable
    where categories like '%4%'
    

    See SQL Fiddle with Demo

    Or you can use the FIND_IN_SET function:

    select name, categories
    from yourtable
    where FIND_IN_SET(4,categories) > 0
    

    See SQL Fiddle with Demo

    My suggestion would be to change your table to not store your data in this comma-separated format, it will cause nothing but problems.

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

Sidebar

Related Questions

Possible Duplicate: MySQL Results as comma separated list Combine Multiple child rows into one
Possible Duplicate: PHP MySQL Search And Order By Relevancy Hi, I have a table
Possible Duplicate: Save Data in Arabic in MySQL database I have a problem with
Possible Duplicate: Special characters in PHP / MySQL I have a problem. I have
Possible Duplicate: MySQL Duplicate rows how to delete duplicate rows from a table in
Possible Duplicate: MYSQL AND OR On Many To Many Table I want to do
Possible Duplicate: mysql custom sort I have an array of IDs: $ids = array(5,
Possible Duplicate: Format mysql datetime with php Well.. I have stored date(c) in Mysql
Possible Duplicate: php/Mysql query with inserting date fails I have a datepicker code below:
Possible Duplicate: ClassNotFoundException com.mysql.jdbc.Driver I have included the mysql-connector-java-5.1.16-bin.jar into my Eclipse library, this

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.