Results 1 to 3 of 3

Thread: Random results and other adventures...

  1. #1
    Join Date
    Dec 2002
    Posts
    2

    Random results and other adventures...

    I am fairly new to mysql and am using it with PHP, and I am curious to know...
    - how can i retrieve random results from a search. ie, if a search yields 10 results, but i only want to choose 3 random results, how can i do this?
    also...
    - when searching a database, how can i check to see if a field has a value? For instance, using:
    SELECT * FROM table WHERE name=.... and only retrieve results for where 'name' has a value.
    i appreciate any assistance you could offer...
    thanks!

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    Using SELECT TOP 3 you can select first three rows but it's not random. It depends on whether you use any kind of ordering both implicit and explict.

    To make it truly random, you may have to write a procedure to hold the result and randomly select 3 rows.

    For the second case you can filter the name by
    AND NAME is not NULL
    AND NAME <> ''

  3. #3
    Join Date
    Dec 2002
    Posts
    2
    thanks! Ill give it a go.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •