一、基本查询语句
mysql> insert into fruits(f_id,s_id,f_name,f_price) values(‘a1’,101,’apple’,5.2),
-> (‘b1’,101,’blackberry’,10.2);
Query OK, 2 rows affected
Records: 2 Duplicates: 0 Warnings: 0
mysql> select *from fruits;
+——+——+————+———+
| f_id | s_id | f_name | f_price |
+——+——+————+———+
| a1 | 101 | apple | 5.2 |
| b1 | 101 | blackberry | 10.2 |
+——+——+————+———+
2 rows in set
二、单表查询(查询单个或多个字段)
mysql> select f_id,f_name from fruits;
+——+————+
| f_id | f_name |
+——+————+
| a1 | apple |
| b1 | blackberry |
+——+————+
2 rows in set
//查询指定记录
mysql> insert into fruits values(‘b4’,106,’Xxx’,1.4);
Query OK, 1 row affected
mysql> select f_name,f_price from fruits where f_price=1.4;
+——–+———+
| f_name | f_price |
+——–+———+
| melon | 1.4 |
| Xxx | 1.4 |
+——–+———+
//查询价格小于5的
mysql> select f_name,f_price from fruits where f_price<5;
+——–+———+
| f_name | f_price |
+——–+———+
| banana | 4.1 |
| melon | 1.4 |
| Xxx | 1.4 |
+——–+———+
3 rows in set
//带between and的范围查询where f_price between 2 and 10;
//带like的字符串匹配where f_name like ‘b%’;
//查询属性为空的字段where c_email is null;
//带add的多条件查询where s_id =’101’ and s_price>10;