Tuesday, September 20, 2011

How To Write a Simple SQL Select Statement in MySQL

Nama: Woody Allen
Tajuk: How To Write a Simple SQL Select Statement in MySQL
Iklan: How To Write a Simple SQL Select Statement in MySQL

Assuming that you are already hooked into a MySQL db or database, there is a tool called MySQL Query browser that would be a good choice to use when you need to make a simple select statement. All you need to do is use the active connection to your database, a query tool like MySQL query browser. Select statements return a certain set of results that is retrieved from a number of other tables. This is particularly useful if you are searching for something in your database.

Creating a new file. The first thing you need to do is to open your MySQL query browser and create a new file. You can also opt to create a new project. This is all depending on your preference.
Selecting the table where you want to extract information from. Your next step is to identify which table you need to sift through to get to the right information. You can do this by selecting from a list of tables that oftentimes is provided by your preferred editor. You can also use the command, "show tables" to display all of the accessible tables in the database that you are accessing now. From the list of tables, you can start selecting the particular table that you need to access. The steps to this are in the next paragraph.

Querying the table. You can do a "SELECT e.* from table_name e" to extract the table that you need to sift through. Remember that you need to specify the actual table name and in this case, replace the "table_name" with the actual name of the table. This would give you all of the existing rows and the columns of this table. You should be able to view this from your own screen.

Filtering the results from the table search. Most often, you do not need all of the data that the search displays. At some point, you need to filter the information. For example, if you only want to show the first 50 hits of the search, then you can key in "SELECT e.* from table_name e limit 50" which will be very useful if you are accessing a huge database.

Other ways to filter. The other types of commands in terms of selecting information that you can use is the ORDER BY which arranges the results in order of your preference, if it is in ascending order etc. You can also do a search by location by keying in WHERE, or by groups by keying in GROUP BY. Other samples of requests are displayed below:


SELECT SKIP 20 FIRST 10 * FROM T order by c, d


These are just the simple examples on how you can do basic extraction from a database. The tip is to know how big of a database you are accessing so that you can immediately limit the results. If you are accessing an extremely huge database, your machine might not be able to handle the results especially if you are using very broad filters. This will make the searching attempt essentially useless. You can also try to narrow down as much as you could the moment you start searching so that you will not waste your time in a trial and error mode in searching for items in the database.

Reposted by:

www .Exabytes .com .my
Malaysia Web Hosting, Malaysia Dedicated Server Provider, Malaysia Domain Registration
Ip Pengirim:

No comments:

Post a Comment