在MS Sql Server查询中? [英] in MS Sql Server Query?
问题描述
大家好,
我有一个表``tbl_student''字段是(名称,类别,年龄,地址)确定.
我输入了记录,
Hi everybody,
I have One Table ''tbl_student'' fields are (Name,Class,Age,Address) OK.
I entered records,
Name Class Age Address
------ ------ ----- --------
Mohan X 18 Erode
Kumar XII 20 Chennai ---->1
Arun XI 19 Trichy
Bala VII 17 Coimbatore ---->2
Vijay VIII 17 Chennai
Karthi X 19 Erode
好吧
我存储了最后的``Kumar''和``Bala''Details(1,2).
如何使用MS Sql查询获取这些最后2条插入的记录?
任何一个已知的plz都告诉我....
来自Mohan.
[edit]已添加代码块,忽略HTML ..."选项已禁用-OriginalGriff [/edit]
Ok.
I stored Finally ''Kumar'' and ''Bala'' Details(1,2).
How I get these Last 2 inserted records using MS Sql Query?
any One Known plz tell me....
By from Mohan.
[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]
推荐答案
尝试:
SELECT * FROM tbl_student WHERE Name=Kumar OR Name=Bala
[edit]糟糕!名称错误...:O-OriginalGriff [/edit]
[edit]Oops! Wrong names...:O - OriginalGriff[/edit]
尝试此链接
获取最新ID和显示 [
try this link
Get Latest Id and Display [^]
您的表中是否有主键或标识?
将ID视为表中的另一列(身份)
You have primary key or identity in your table?
Consider ID as another column(Identity) in table
ID Name Class Age Address
-- ------ ------ ----- --------
1 Mohan X 18 Erode
2 Kumar XII 20 Chennai ---->1
3 Arun XI 19 Trichy
4 Bala VII 17 Coimbatore ---->2
5 Vijay VIII 17 Chennai
6 Karthi X 19 Erode
现在,您可以通过以下查询获取最后插入的记录
Now you can get last inserted records by following query
SELECT TOP 2 * FROM tbl_student ORDER BY ID DESC--For last 2 inserted records
SELECT * FROM tbl_student WHERE ID =(SELECT Max(ID) FROM tbl_student)--For last inserted record
根据您的条件自定义查询.
Customize query based on your criteria.
这篇关于在MS Sql Server查询中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!