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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:49:55+00:00 2026-05-17T18:49:55+00:00

I have a MySQL table that looks like this: Table: Designer id: integer name:

  • 0

I have a MySQL table that looks like this:

Table: Designer
  id: integer  
  name: String
  gallery: string

The gallery row can contain a string value like 23,36,45

Now I want to do a query similar to this:

SELECT * FROM Designer WHERE gallery = '36'

I know I kan use LIKE, but that is not precices enough. That could return both 36 and 136.

I also know I could create another table which links designer and gallery. But since this is not going to be a huge table, I’m adding the foreign gallery ID Key to the gallery row. And I’m lazy right now 😉

So how can I select a row that has the number 36?

UPDATE
Ok, since I’m getting nailed for poor design (yes I know it was), I See the obvious now.

A designer can have many galleries, but a gallery can only belong to one designer.
Therefore I only need to add designer ID as a foreign key to the gallery table.

Simple. But not always logical when it’s 3AM and you’ve been workign for 15 hours 😉

  • 1 1 Answer
  • 3 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-17T18:49:55+00:00Added an answer on May 17, 2026 at 6:49 pm

    You really shouldn’t store your data like that since it makes queries horribly inefficient. For that particular use case, you can (if you don’t care about performance) use:

    select * from designer
        where gallery like '36,%'
           or gallery like '%,36'
           or gallery like '%,36,%'
           or gallery = '36'
    

    This will alleviate your concerns about partial matches since something like 136 will not match any of those conditions but 36 in any position will match.


    However, despite your protestations to the contrary, what you should do is re-engineer your schema, something like:

    designer:
        id             integer primary key
        name           varchar(whatever)
    designer_galeries:
        designer_id    integer foreign key references designer(id)
        gallery        string
        primary key    (designer_id,gallery)
    

    Then your queries will be blindingly fast. One of the first things you should loearn is to always design your schema for third normal form. You can revert to other forms for performance once you understand the trade-offs (and know how to mitigate problems) but it’s rarely necessary unless you database is horribly convoluted.

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

Sidebar

Related Questions

I have a table that looks something like this: CREATE TABLE student_results(id integer, name
I have a MySQL table that looks like this: id (int primary) name (text)
I have a mysql table that looks something like this: Row 1: 'visitor_input_id' =>
I have a Mysql table that looks like this: +-------+ | NAME | +-------+
I have a mysql table that looks like this: id col2 col3 col4 1
I have a MySQL table that looks like this: `id` int(10) unsigned NOT NULL
I have a MySQL table that looks something like this: +-----+------------+ | id |
I have a MySQL database table called Participant that looks something like this: (idParticipant)
Suppose I have a MySQL table called MyTable, that looks like this: +----+------+-------+ |
I have a MySQL table that looks something like this: |---ID---|---COUNTER---| | 1 |

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.