We accept safe and secure Credit Card and PayPal Payments.
 
Perl Scripts

All Count
Attachment Mailer
Perl Scripts Build A FAQ Plus
Perl Scripts Clock In Center
eBackup Automated
Easy Poll
eSurvey
Fetch a File
Form Maker
Mailing List Server
MySQL Mate
PDF Creation
QCart
Quick Fix
Quote of the day
Speed Search
Task Manager
Traffic Pack
Upload Plus
Upload Gold
Upload Pro
Website Manager

 
Free Perl Downloads

Free Perl Scripts Main Page
Free Perl Scripts 404 Alerter
AccessLog Viewer
Build A FAQ
PHP Scripts eBackup
Free PHP Scripts ErrorLog Viewer
eVars - Server Info
HT Pass Creator
Upload Lite
Website Manager

 
JavaScripts

Free Java Scripts Alert Boxes
Free JavaScripts Browser Sniffer
Check email
Generators
Slide Show
Sudoku
Window Maker
More...

 
Extra Utilities

ASP Scripts Ascii Codes
Free ASP Scripts Color Picker
Font Finder
HT Pass Creator
Meta Cloak
Meta Magic
Pano Zooms
SlideShow
Server Size

 
Online Tutorials

Free HTML Scripts Glossary
Free HTML Scripts HTML
JavaScript
MySQL
SSI
Build Traffic
Other

 
Miscellaneous

About Us
Graphics
Testimonials
Installations
Latest versions

 
Hawk Eye in Tennis

Should Hawk Eye replace linesmen and lineswomen at all tennis tournaments?







 
View all Polls

Run Polls on your site

Run your own Surveys

 
Store Download FAQs Contact Us Support Programming Policies  
Select Statement     List of Categories

Page 1 Page 2

  1. How do I select a record from a mysql table?

  2. How do I select records from select records?

  3. How do I select specific records?

  4. How do I quote a value and whay should I?

  5. How I do select specific records using regular expressions?

  6. How do I select random records?

  7. How do I select unique or distinct records?

  8. How do I select a limited number or records?

  9. How do I simply data keys returned in selections with complext column or functions names?

  10. How do I order the selected records returned?







  1. How do I select a record from a mysql table?

    The statement below will select all columns (*) from the tablename you specify.
    SELECT * FROM tablename
    


    Top of Page


  2. How do I select records from select records?

    By using the HAVING clause. This is useful for performing functions on data already selected, rather than on the entire table.
    SELECT * FROM tablename WHERE age > 21 HAVING weight < 50 
    


    Top of Page


  3. How do I select specific records?

    The statement below will select all columns (*) from the tablename you specify, where the column you specify contains the value you specify.
    SELECT * FROM tablename WHERE column = ''
    

    When specifing value, be sure that unless the values are numbers, that you quote them. You may also want to quote the value so that any quotes within the value are escaped. Here's two more examples.

    SELECT * FROM tablename WHERE age > 40 && age < 50
    
    SELECT * FROM tablename WHERE name = 'John'
    


    Top of Page


  4. How do I quote a value and whay should I?

    Quoting value will help ensure server 500 errors are avoided. If you're querying your databases using variables, you're not always sure what the values hold, and often they do hold meta characters which need to be escaped.

    Let's you're searching for family names, which can include names like O'Connor. The qoute in the name would cause an error if you where quoting the value of your test. Quoting the values using MySQL's quote function ensure all metacharacters, including quotes are properly escaped.

    $VAR{name} = $DB->quote($VAR{name});
    
    SELECT * FROM members WHERE surname = $VAR{name}
    


    Top of Page


  5. How I do select specific records using regular expressions?

    Yes, MySQL does support regular expressions. And it also has a much simpler method where by you can select records that contain the string you're seeking. You do this by using either the LIKE or RLIKE clause.

    To select records using the LIKE clause, you pad the value with a % sign on each side to act as a wildcard. The following statement :

    SELECT * FROM tablename WHERE column LIKE '%Ron%'
    
    would return records that contained 'Ronald' and 'Ronny'. Conversely, if you didn't like Ron, you could say :
    SELECT * FROM tablename WHERE column NOT LIKE '%Ron%'
    
    to return all records that did NOT contain the string 'Ron'.

    RLIKE is similar to LIKE except that it takes and acts upon regular expressions. Regular expressions are a topic within themselves, so I'll just give an example here. MySQL does support the full Unix regular expression syntax.

    SELECT * FROM tablename WHERE column RLIKE '^Ron.*'
    
    This is similar to LIKE example above, but is telling MySQL to search for values that begin with 'Ron' by using the caret (^). So a record with 'Cron' would not be returned.

    Top of Page


  6. How do I select random records?

    One method is to select your record or records, limit the selection to 1 or more records, then order the results randomly. All of this can be achieved with mySQL statements.
    SELECT * FROM tablename WHERE live = 1 ORDER BY RAND() LIMIT 1


    Top of Page


  7. How do I select unique or distinct records?

    SELECT DISTINCT colname FROM tablename


    Top of Page


  8. How do I select a limited number or records?

    The LIMIT keyword takes either 1 or 2 arguments. If using just 1 argument, it will return the number or records you specify. As in :
    SELECT * FROM tablename WHERE live = 1 LIMIT 1
    
    Or, you can skip the first 20 records, and select the following 10 records, as in :
    SELECT * FROM tablename LIMIT 20,10


    Top of Page


  9. How do I simply data keys returned in selections with complext column or functions names?

    By using aliases.
    SELECT FROM_UNIXTIME(UNIX_TIMESTAMP(), '%i') AS easydate FROM tablename
    


    Top of Page


  10. How do I order the selected records returned?

    You can order the results returned by one or more columns separated by commas. When ordering by columns, the data type is taken into account, and results are ordered by the column names in the order you define them.

    For example, if you have a column named 'age' but the column is defined as a VARCHAR(255) rather than INT(11) type, the results will be ordered in such a way that the number 112 comes before the number 24, because 1 is less than 2 in the alphabet. If you're columns are well defined though, as integers, 112 is of course greater than 24 so you can expect MySQL will return the results in the expected order.

    SELECT * FROM tablename WHERE age > 40 ORDER BY age
    
    Or you could use
    SELECT * FROM tablename WHERE age > 40 ORDER BY age, height, weight LIMIT 20
    
    Which would return no more than 20 records, with people who are aged exactly 45, sorted by their height, then their weight. This would place the people weighing less, above the others of the same age.

    You can also reverse the sorting using the DESC keyword. You'd need to define it with each column you're wanting sorted in descending order.

    SELECT * FROM tablename WHERE age > 40 ORDER BY age DESC, height, weight DESC LIMIT 20


    Top of Page


Page 1 Page 2

Was this page helpful?    
Speed Search our site
Plesk Hosting
Linux servers with Plesk Control Panel, cgi-bin, crontab manager, Mysql, PHP and ASP.

Survey Software
Create unlimited web based surveys on your website from your website

Discounted Scripts
Subscribe to our periodial newsletter to receive special offers.

Bathroom Hygiene
How often do you thoroughly clean your bathroom?








View all Polls

Run Polls just like this one on your website!


About us | Contact us | Script FAQs | Script Support | Website Hosting | Our Policies | Store | Testimonials
Subscribers log in here. Subscribe to our periodical newsletter for special offers on commercial scripts, hosting, exciting business opportunities, and industry news and events. Our Mailing List Software is powered by Consolidator    
HTML Plain text
©1999 - 2015 All content Copyright PerlScriptsJavaScripts.com Proudly hosted by LinuxHostingPlans.com