Results 1 to 4 of 4

 

Thread: SQL select statements

  1. #1
    apg1985's Avatar
    Registered User

    Status
    Offline
    Join Date
    Mar 2011
    Posts
    412
    Thanks
    1
    Thanked 17 Times in 11 Posts


    Hi,

    How would you filter rows in a table which contained a word?

    Say if I had a column in the db called paint, the rows for this column where say:

    cheap red paint
    cheap blue paint
    very cheap red paint

    how would I filter on the word 'red' so it pulled:

    cheap red paint
    very cheap red paint

    Ive tried this -> "SELECT * FROM test WHERE paint LIKE '%red%'"

    but this will only grab the records where 'red' is a the beginning of the sentence, I need it to look through the sentence for the word 'red' and pull it out.

    Cheers

  2. #2
    Registered User

    Status
    Offline
    Join Date
    May 2010
    Posts
    44
    Thanks
    0
    Thanked 7 Times in 7 Posts
    I think something like this may work SELECT LEFT( paint, LOCATE( "red", paint ) ) FROM table;

    MySQL locate() function < MySql Tutorial | w3resource

  3. #3
    nick-harper's Avatar
    Registered User

    Status
    Online
    Join Date
    Feb 2011
    Posts
    91
    Thanks
    0
    Thanked 4 Times in 4 Posts
    That code "should" pick it anything with the word red in?

  4. #4
    ShagaaDaggaDoo

    Status
    Offline
    Join Date
    Aug 2003
    Location
    Surrey
    Posts
    1,150
    Thanks
    0
    Thanked 9 Times in 6 Posts
    Use mysql fulltext search

    Using MySQL Full-text Searching



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2