SQL 2005中的嵌套选择查询 [英] nested select query in sql 2005
本文介绍了SQL 2005中的嵌套选择查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个桌子.
1.管理员(用户名,密码)
2.User(用户名,类型)
我已经提供了用户名和密码,我想从User表中检索用户类型.
I have two table.
1.Admin(username,password)
2.User(username,type)
I have given username and password and I want retrieve the type of user from User table.
推荐答案
select type from [User] where username = 'the_username_wanted'
一个简单的连接就是你要的
a simple join is what you are after
SELECT
*
FROM
Admin a
JOIN
User u
ON
a.username = u.username
WHERE
a.username = @username
AND
a.password = @password
关于CP的连接,也有不错的文章此处 [
There is also a good article on CP about joins here[^]
select type from user where username = @username
@username是您必须将其传递给存储过程或sql语句的参数.
@username is a parameter that you have to pass it to stored procedure or sql statement.
这篇关于SQL 2005中的嵌套选择查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文