SQL语言入门教程:第三课数据查询

来源:互联网 发布:阿里巴巴淘宝城规划 编辑:程序博客网 时间:2024/06/15 14:00
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
第三课数据查询

在众多的SQL命令中,select语句应该算是使用最频繁的。select语句主要被用来对进行查询并返回符合用户查询标准的结果数据。Select语句的语法格式如下:

selectcolumn1[,column2,etc]fromtablename

[wherecondition];

([]表示可选项)

select语句中位于select关键词之后的列名用来决定那些列将作为查询结果返回。用户可以按照自己的需要选择任意列,还可以使用通配符“*”来设定返回表格中的所有列。

select语句中位于from关键词之后的表格名称用来决定将要进行查询操作的目标表格。

Select语句中的where可选从句用来规定哪些数据值或哪些行将被作为查询结果返回或显示。

在where条件从句中可以使用以下一些运算符来设定查询标准:

=等于

>大于

<小于

>=大于等于

<=小于等于

<>不等于

除了上面所提到的运算符外,LIKE运算符在where条件从句中也非常重要。LIKE运算符的功能非常强大,通过使用LIKE运算符可以设定只选择与用户规定格式相同的记录。此外,我们还可以使用通配符“%”用来代替任何字符串。举例如下:

selectfirstname,lastname,city

fromemployee

wherefirstnameLIKE‘E%’;

(注意,字符串必须被包含在单括号内)

上述SQL语句将会查询所有名称以E开头的姓名。或者,通过如下语句:

select*fromemployee

wherefirstname=‘May’;

查询所有名称为May的行。

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击