多表查询的一些技巧

1、基本方法:From 后面可以接多个表名,表与表之间用逗号隔开,查询字段之间要加上表的名字。
例如:Select table1.column1, table2.column1 from table1, table2
2、表别名:可以为表设置别名,以简化输入,方法是直接在表名后加空格,接你设定的别名。
例如:Select a.column1, b.column2 from table1 a, table2 b
3、运算:选取的过程也可以进行一些简单运算,包括逻辑运算和数学运算。
例如:select isnull(a.column1, b.column2), case a.column2 when true then a.column3 else a.column4 from table1 a, table2 b
4、字段别名:运算结果给成的新字段是没有字段名的,为了提取方便,最好给它们设定别名,就像给正常的字段设定别名一样。
例如:select isnull(a.column1, b.column2) as column_status from table1 a, table2 b

posted @ 2012-11-20 14:21  蚂蚁乙  阅读(126)  评论(0编辑  收藏  举报