全面接触SQL语法(3)

  order by条件语句

  此条件子句,通常与select语句合并使用目的是将查询的结果,依照指定字段加以排序。


  select fieldlist


  from table


  where selectcriteria


  order by field[asc|desc][,field2[asc|desc][,...]] 


  fieldlist

  欲查询的字段名称。其中可以与all,distinct,disinctrow,或top一起来使用。 


  table


  欲查询的表格名称。 


  selectcriteria


  查询的标准设置。 


  field1

  指定要依照那个字段作为排序的依据,若是你没有加上order by查询出的数据集将不会作排序的操作。 

  asc

  递增顺序类别。(默认值) 


  desc

  递减顺序类别。

  例如:

  或是我们要将输出数据依据出生的先后次序排列,可以利用下面的命令。


  select 姓名,生日

  from 职员表格


  order by 生日

  select lastname,firstname

  from employees

  order by lastname asc; 

  in 条件子句

  指定要速胜哪一个外部数据库的表格。(必须是microsoft jet数据库引擎所可以连接的数据库,如dbase,paradox等等)

  
select|insert]into destination in
{path|["path" "type"]|[""[type;database=path]]}
from tableexpression in
{path|["path" "type"]|[""[type;database=path]]} 
destination


  欲插入数据的外部表格名称。 

  tableexpression

  表格名称或是被读取数据的表格名称。这个参数可以是一个单一的表格名称,或是一段已经被存储的sql查询等。 

  path

  包含该表格的完整路径名称。 

  type

  数据库的类型名称, 通常是当数据库部属于jet database时才会使用。(例如:dbase iii,dbase iv,paradox 3.x,paradox 4.x,或 btrieve) 

  例如:下面这两段的意义相同


parta....from table
in ""[dbase iv;database=c:\dbase\data\sales;];

partb....from table
in "c:\dbase\data\sales" "dbase iv;"



  例如:microsoft jet database


select 顾客编号
from 顾客表格
in customer.mdb
where 顾客编号 like "a*";
其中customer.mdbo 为jet database 的数据库名称,其中包含了顾客表格。

例如:dbase iii or iv
select 顾客编号
from 顾客表格
in "c:\dbase\data\sales" "

dbase iv;"
where 顾客编号 like "a*";
所以当我们使用不同于access 的数据库时,必须指明该数据库的类型名称。

 以上就是全面接触SQL语法(3)的内容,更多相关内容请关注PHP中文网(www.)!