help with a query please

Discussion in 'MySQL' started by JEET, May 28, 2007.

  1. #1
    Hi,
    (mysql, php question)
    The table is something like below:

    field1 field2 field3

    I need to search "field1" and sort by "field2". I know the query for that, but here's a problem:

    The search term is "hello jeet", (2 words)
    How do I search for first word, and then search for word2 and sort the "final" result by field2?
    I think I'll need a temporary table in between. Is that right?
    If there's an easier way of doing this, then please let me know. :) (with array, or some query I'm forgetting about...)

    Please note that the "final" output needs to be sorted on field2. Doesn't matter which word is searched first and so on. Plus there can be more than 2 words...

    Thanks :)
    jeet
     
    JEET, May 28, 2007 IP
  2. Clark Kent

    Clark Kent Guest

    Messages:
    122
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    select field1, field2, field3 from table1 where field1 like ('an%') or field1 like ('al%') or field1 = 'test' order by field2
     
    Clark Kent, May 28, 2007 IP
    JEET likes this.
  3. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #3
    Nice! :)
    That was easy. Why didn't I think of that... ;)
    Green reps added :)
    Best regards
     
    JEET, May 28, 2007 IP
  4. Clark Kent

    Clark Kent Guest

    Messages:
    122
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You welcome my friend :)
     
    Clark Kent, May 28, 2007 IP