Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

MySql search [partial words?]

  • 07-02-2010 07:38PM
    #1
    Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭


    Hey Guys,
    in a rush so cant research but

    Select * From products where description = "blue cheese"


    how can i query so same result would display if description = blue

    or cheese



    thanks


Comments

  • Closed Accounts Posts: 404 ✭✭kenbrady


    Placebo wrote: »
    Hey Guys,
    in a rush so cant research but

    Select * From products where description = "blue cheese"


    how can i query so same result would display if description = blue

    or cheese



    thanks
    don't know how to do it, but if you can get the search string before hand and parse it

    where
    description like '%blue%'
    or
    description like '%cheese%';


  • Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭Placebo


    That does work properly

    it returns STEAKS if i search for TEA

    any other suggestions? rather not parse, codes a bit complex

    thanks,


  • Registered Users, Registered Users 2 Posts: 515 ✭✭✭NeverSayDie


    Assuming you're not in a position to rearrange your schema to include keywords or a basic index you could search against more efficiently, you could look at full-text indexing and searching of the descriptions, which should do the job. Complex stuff in general, but MySQL takes care of all the tricky bits. There is a performance impact of course, but for (presumably) short descriptions it shouldn't be an issue.

    See here;
    http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
    http://devzone.zend.com/article/1304


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Select * From products where description like "blue%"

    Should return everything that starts with blue. Blue cheese, blue stocking, blue nun.

    Select * From products where description = "%cheese"

    Will return everything that ends with cheese. If you uses "%tea%" then you've wild cards before and after tea, hence steaks is getting returned.


Advertisement