您的位置:首页 > 数据库

notes/tips during sql tutorial learning

2009-08-10 19:43 471 查看
below are some notes/tips during learning sql @ http://www.w3schools.com/SQl/sql_syntax.asp
1. Keep in mind that sql is not case sensitive

2. The DISTINCT keyword is used to return only distinct(different) values. It's syntax is , for example:

   select DISTINCT City from Persons

3. The BETWEEN keyword can be used to select a range of data between two values, the syntax is

   SELECT column_names

   FROM table_name

   WHERE column_name

   [NOT]BETWEEN value1 AND value2

  

   To select the data out of the range, NOT BETWEEN can be used.

   Note: BETWEEN is treated differently in diff DB implementations:

         1. some will exclude the range values

         2. some will include the range values

         3. some will include the first range and exclude the second range.

4. ORDER BY is used to sort the result:

   SELECT column_name(s)

   FROM table_name

   [WHERE column_name]

   ORDER BY column_name(s) ASC|DESC

5. GROUP BY is used in conjunction with aggregate function to group the result-set by one or more columns:

   SELECT column_name(s),aggregate_function(column_name)

   FROM table_name

   [WHERE column_name(s)]

   GROUP BY column_name(s)

6. INSERT INTO:

   INSERT INTO table_name

   VALUES(value1,value2,valuen)

  

   INSERT INTO table_name(column1,column2,columnn)

   VALJUES(value1,value2,valuen)

7. UPDATE:

   UPDATE table_name

   SET column1=value1,column2=value2,columnn=valuen

   [WHERE column_name]

   Note: if WHERE clause is omitted, all records will be updated.

  

8. DELETE:

   DELETE from table_name

   [WHERE column_name(s)]

   Note: if WHERE clause is omitted,all records will be deleted.                

9. SQL wildcards

   wildcards must be used in LIKE operator

   %           : zero or more any characters

   _           : one single character

   [charlist]  : any one character in the list

   [^charlist] | [!charlist]   : any one character not in the list

10. LIKE:

   SELECT column_name(s)

   FROM table_name

   WHERE column_name LIKE pattern
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息