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

  • Home
  • SEARCH
  • 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 7488383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:54:11+00:00 2026-05-29T14:54:11+00:00

I am quite new at database programming and I am having trouble doing searches

  • 0

I am quite new at database programming and I am having trouble doing searches in my database. I have a table with a column named Required_Items, it is just a list of required items separated by ‘;’. I can’t get the server to return the rows when querying :

'SELECT * FROM The_Table WHERE Required_Items LIKE '%item1%' '

It seems that the database can’t find that item in the column. The problem is that I want to be able to return rows that contain ALL the items. I would try something like:

'SELECT * 
 FROM The_Table 
 WHERE Requiered_Items LIKE '%item1%' AND 
       Requiered_Items LIKE '%item2%' AND 
       Requiered_Items LIKE '%item3%' AND//etc...

How can I do that knowing that there will be a variable number of these “items” to test ?

  • 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-29T14:54:12+00:00Added an answer on May 29, 2026 at 2:54 pm

    When I have problems like this it invariably turns out to be that my comparison strings simply don’t match. (That’s not to say they don’t look like they match.) Common reasons are spelling mistakes, upper vs lower case issues, characters (particularly spaces) aren’t what they appear to be. Do you have spaces in any of your ‘like’ comparisons?

    How did you get the data into the database? Did you copy it from Word or Excel and paste it into the SQL query builder, or somethng of that nature? That can cause problems if you’re not careful.

    And of course you know that ALL of your ‘like’ comparisons must match in order to get data…?

    Here’s an example of what may be happening:

    If the ‘Required Items’ field = ‘Bat, Ball, Glove, Cap, Helmet, Water Battle’
    then these will both fail:

    ...where Required_Items like '%Bat%'
             and              ...'%Water Bottle%'
    
    ...where Required_Items like '%Glove%'
             and              ...'%Water Bottle%'
    

    (Because ‘Water Bottle’ is spelled incorrectly in the database)

    You can troubleshoot for this kind of problem by having one item at a time in your where clause until you find the one that fails.

    Regarding a variable number of items, using the data the way you have it set up (all items in one csv field) your code might be cleanest if you used dynamic sql. That’s where you build a query in a string vaiable and execute the variable. Search for “Dynamic SQL”.

    All that said, the preferred method of storing this kind of data in a relational database is to create maintainable relationships between entities. Your data would be much friendlier if you broke the items out into a structure like this:

    __The_Table_______      __Thing_Items____      __Items_______________
    Thing_ID  Thing         Thing_ID  Item_ID      Item_ID  Item               
    --------  --------      --------  -------      -------  --------------     
    T1        Baseball      T1        i1           i1      Ball               
    T2        Football      T1        i2           i2      Bat                
    T3        Fishing       T1        i5           i3      Shoulder Pads      
                            T2        i1           i4      Worms              
                            T2        i3           i5      Water Bottle       
                            T2        i5                                       
                            T3        i4                                       
                            T3        i5                                       
    

    This structure would make handling unknown numbers of items very easy to deal with.

    If you can’t solve this, post actual code and actual data if you can.

    Scott

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

Sidebar

Related Questions

I am quite new at database programming and I am having trouble doing searches
I am quite new to SQLAlchemy, or even database programming, maybe my question is
I'm quite new to Zend and the database classes from it. I'm having problems
I'm quite new to programming. I have an ASP.NET 4.0 application and I would
I'm quite new to subject of writting stored function for mySQL database, hence i'm
I'm quite new to programming, and I was wondering if there is a good
Hi I am quite new to php but i have been following some tutorials
I'm quite new to php and have been reading Larry Ullman book to develop
I'm quite new to OpenId and I'm having a bit of a problem understanding
I'm fairly new to Visual Studio (specifically Visual Basic .NET) but have been programming

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.