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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

MySql search [partial words?]

  • 07-02-2010 6: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