To select all records from a table we use following query
Syntax
1 | select * from table_name; |
To select all row of student we use
1 | select * from student; |
It will show following result
1 2 3 4 5 6 7 8 9 10 | mysql> select * from student; +----+-------------+-----------+-------+------+ | id | name | address | class | age | +----+-------------+-----------+-------+------+ | 1 | Ram Kumar | New Delhi | 5th | 10 | | 2 | Mohan Kumar | New Delhi | 5th | 10 | | 3 | Sohan Kumar | Bhopal | 5th | NULL | | 4 | Rohan Kumar | NULL | 5th | 11 | +----+-------------+-----------+-------+------+ 4 rows in set (0.00 sec) |
To select perticular column from table we use
1 | select column1,column2, ..column n from table_name; |
If we want to select id and name of student the we will write
1 | select id,name from student; |
ther is no limit we can select one to all column by specifying the column name.
We can also select table detail based on some criteria for that we use following query
1 | select * from table_name where field=value; |
We want to fetch all record of student whose id is 1.
for that we write
1 | select * from student where id=1; |
If you want to fetch detail of student whose age is 10
for that we will use
1 | select * from student where age=10; |
where can also set multiple condition with where clause
1 | select * from student where address='New Delhi' and age=10; |
Selecting column with null value we write following query
1 | select id,name from student where age is null; |
To check for null value we use is null with field name.