MYSQL05: Retrieving data using SELECT
Once the tables are populated with data, we can ask for the data from the table. To retrieve the data from table, SELECT command is issued.
this will gives us:
although it is possible to get the entire table into out program and then process them by our self, we make use of all the capability provided by database server to help lessen the programming.
SELECT (field1, field2 ...) FROM
tableName;
for example, to get id, name and age from the students table, the SELECT statement is written like this:
SELECT (id, name, age) FROM
students;
this will return all the data with every fields from the
students table. Another most common way is using asterisk symbol.
SELECT * FROM students;
both the SQL statement above will return following result. (table with dash lines to distinguish the table in database and table you get in your program)
both the SQL statement above will return following result. (table with dash lines to distinguish the table in database and table you get in your program)
Id
|
name
|
age
|
1
|
Calvin
|
12
|
2
|
Joe
|
15
|
3
|
Rosy
|
17
|
We can also retrieve only certain field from the table. For example, to retrieve only the name from the entire table
SELECT (name) FROM students;
this will gives us:
name
|
Calvin
|
Joe
|
Rosy
|
although it is possible to get the entire table into out program and then process them by our self, we make use of all the capability provided by database server to help lessen the programming.
Comments
Post a Comment