ghjzzhg的博客

学习使我快乐,但我快乐了吗???

Mysql查询语句

mysql查询语句

SELECT column_name,column_name
FROM table_name
[WHERE Clause]
[OFFSET M ][LIMIT N]

1、where条件查询

SELECT field1, field2,...fieldN FROM table_name1, table_name2...
[WHERE condition1 [AND [OR]] condition2.....
2、update修改语句

UPDATE table_name SET field1=new-value1, field2=new-value2
[WHERE Clause]
3、删除表

DELETE FROM table_name [WHERE Clause]
4、like模糊查询,查询包含的字母、字符、汉字等

SELECT field1, field2,...fieldN 
FROM table_name
WHERE field1 LIKE condition1 [AND [OR]] filed2 = '%value'
5、组合、合并查询

SELECT expression1, expression2, ... expression_n
FROM tables
[WHERE conditions]
UNION [ALL | DISTINCT]
SELECT expression1, expression2, ... expression_n
FROM tables
[WHERE conditions];
6、排序查询

SELECT field1, field2,...fieldN table_name1, table_name2...
ORDER BY field1, [field2...] [ASC升序 [DESC降序]]
7、分组查询----分组时可以使用COUNT, SUM, AVG函数

SELECT column_name, function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name;
8、连接查询

内连接(等值连接)

SELECT a.runoob_id, a.runoob_author, b.runoob_count FROM runoob_tbl a INNER JOIN tcount_tbl b ON a.runoob_author = b.runoob_author

这里也可以使用where语句,查询结果相同

SELECT a.runoob_id, a.runoob_author, b.runoob_count FROM runoob_tbl a, tcount_tbl b WHERE a.runoob_author = b.runoob_author

左连接:

SELECT a.runoob_id, a.runoob_author, b.runoob_count FROM runoob_tbl a LEFT JOIN tcount_tbl b ON a.runoob_author = b.runoob_author

右连接

SELECT a.runoob_id, a.runoob_author, b.runoob_count FROM runoob_tbl a RIGHT JOIN tcount_tbl b ON a.runoob_author = b.runoob_author




阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载,如果你非要转载,那能怎么办呢? https://blog.csdn.net/ghjzzhg/article/details/78533143
文章标签: mysql select 查询
个人分类: 数据库
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭