Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

MySql search [partial words?]

Options
  • 07-02-2010 7:38pm
    #1
    Registered Users 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 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 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 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