SQL学习——基本语法
以下是一些主要的SQL语句的语法实例
SELECT(查询某列) SELECT column_name(s) FROM table_name SELECT DISTINCT(消除重复的元组) SELECT DISTINCT column_name(s) FROM table_name SELECT * (查询表中的所有数据) SELECT * FROM table_name WHERE(范围限定) SELECT column_name(s) FROM table_name WHERE column_name operator value LIKE (匹配查询,注意:有5种通配符) SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern ORDER BY (排序:ASC升序,DESC降序) SELECT column_name(s) FROM table_name ORDER BY column_name [ASC|DESC] INNER JOIN(内连接) SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name=table_name2.column_name LEFT JOIN (左外连接) SELECT column_name(s) FROM table_name1 LEFT JOIN table_name2 ON table_name1.column_name=table_name2.column_name RIGHT JOIN(右外连接) SELECT column_name(s) FROM table_name1 RIGHT JOIN table_name2 ON table_name1.column_name=table_name2.column_name FULL JOIN (全外连接) SELECT column_name(s) FROM table_name1 FULL JOIN table_name2 ON table_name1.column_name=table_name2.column_name INSERT INTO (插入数据) INSERT INTO table_name VALUES (value1, value2, value3,....) or INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,....) UPDATE (修改数据) UPDATE table_name SET column1=value, column2=value,... WHERE some_column=some_value DELETE (删除数据) DELETE FROM table_name WHERE some_column=some_value or DELETE FROM table_name (Note: Deletes the entire table!!) DELETE * FROM table_name (Note: Deletes the entire table!!)