To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here

HOME News MS SQL Oracle DB2 Access MySQL PHP Scripts Books Links DBA Talk


Go Back   Database Journal Forums > Related Sites > SQL Course

SQL Course SQL Course > Ask questions about the lessons on SQL Course 1 and 2. If you have problems > with the interface, please post in the Feedback forum

Reply Post New Thread
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 12-29-2002, 06:55 PM
Count_Rugen Count_Rugen is offline
Junior Member
 
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!
Reply With Quote
  #2  
Old 12-30-2002, 10:05 AM
skhanal skhanal is offline
Experts
 
Join Date: Nov 2002
Location: New Jersey, USA
Posts: 3,369
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 <> ''
Reply With Quote
  #3  
Old 12-30-2002, 06:36 PM
Count_Rugen Count_Rugen is offline
Junior Member
 
Join Date: Dec 2002
Posts: 2
thanks! Ill give it a go.
Reply With Quote
Reply Post New Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 05:46 AM.


DatabaseJournal Recent Articles


 » Preparing To Upgrade Access Tables to SQL ...

 » Microsoft Windows PowerShell and SQL Serve...

 » New MySQL Enterprise with Query Analyzer B...

 » Quest Software Strengthens Committment to ...

 » Oracle Unveils New Event-Driven Middleware...

Search Database Journal:
 





Acceptable Use Policy

JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.