Saturday 23 July 2016

Get the data from table

By using SELECT statement, you can get the data from table.


SELECT * FROM employee;
Above statement return all the records from table employee;
mysql> DESCRIBE employee;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | YES  |     | NULL    |       |
| name  | varchar(20) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> 
mysql> SELECT * FROM employee;
+------+--------------+
| id   | name         |
+------+--------------+
|    1 | Hari Krishna |
|    2 | Gopi         |
|    3 | Sudhir       |
+------+--------------+
3 rows in set (0.00 sec)


You can also specify specific field to display.
mysql> SELECT name FROM employee;
+--------------+
| name         |
+--------------+
| Hari Krishna |
| Gopi         |
| Sudhir       |
+--------------+
3 rows in set (0.00 sec)


You can query for multiple fields at a time.
mysql> SELECT name, id FROM employee;
+--------------+------+
| name         | id   |
+--------------+------+
| Hari Krishna |    1 |
| Gopi         |    2 |
| Sudhir       |    3 |
+--------------+------+
3 rows in set (0.00 sec)






Previous                                                 Next                                                 Home

No comments:

Post a Comment