[mysql] LIKE and RND() in the same query?

Discussion in 'MySQL' started by 123GoToAndPlay, Apr 17, 2009.

  1. #1
    How can i get this to work?

    CODE]SELECT * FROM tbl WHERE title LIKE '%test%' ORDER BY RND() LIMIT 2[/CODE]

    i get
    FUNCTION dbName.RND does not exist

    Any suggestions?
     
    123GoToAndPlay, Apr 17, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Should be:

    SELECT * FROM tbl WHERE title LIKE '%test%' ORDER BY RAND() LIMIT 2
     
    jestep, Apr 17, 2009 IP
  3. kjambu

    kjambu Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    and if you are really for rnd() the function is round(...)

    here is a help link
    http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_round

    hope it helps!;)
     
    kjambu, Apr 17, 2009 IP
  4. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    @jestep, sharp tx man.
     
    123GoToAndPlay, Apr 17, 2009 IP
  5. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    @kjambu i was looking for random not the math round
     
    123GoToAndPlay, Apr 17, 2009 IP