SELECT 选择<pre name="code" class="sql"><pre name="code" class="sql">
select top 1 * from table_name where name1 = value1 order by sortvalue desc
INSERT 插入
insert into table_name (name1,name2) values(value1,value2)
select @@identity
UPDATE 更新
update table_name set name1 = value1 where id = 1
DELETE 删除
delete form table_name where id = 1
SELECT COUNT 行数
select count(id) as undoid from table_name where state='undo'
select count(distinct username) from table_name where username is not null
DISTINCT 不重复
select distinct name1 from table_name
LIKE(开头,结尾,包含)
select * from Persons where city like 'N%'
select * from Persons where city like '%g'
select * from Persons where city like '%lon%'
BETWEEN 范围值(含或未含取决于数据库差异)
select column_name(s) from table_name where column_name between value1 and value2
IN 选取包含值
select * from Persons where LastName in ('Adams','Carter')
Alias 别名
select po.OrderID, p.LastName, p.FirstName
from Persons AS p, Product_Orders as po
where p.LastName='Adams' and p.FirstName='John'
'不使用别名的select语句:
select Product_Orders.OrderID, Persons.LastName, Persons.FirstName
from Persons, Product_Orders
where Persons.LastName='Adams' and Persons.FirstName='John'
更多资料参照:
http://www.w3school.com.cn/sql/
问题集锦:
关于Access数据库中同时使用top和order by超出条数(并列排名)的解决办法?
Access默认先排序order by,以排序值作为索引,然后返回top
规定的(索引)条数。
解决办法:order by后加入其他唯一值的记录名(id),这样就没事了。