Click here to Skip to main content
15,885,680 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

SQL
select type from [User] where username = 'the_username_wanted'
 
Share this answer
 
a simple join is what you are after

SQL
SELECT
    *
FROM
    Admin a
JOIN
    User u
ON
    a.username = u.username
WHERE
    a.username = @username
AND
    a.password = @password


There is also a good article on CP about joins here[^]
 
Share this answer
 
v2
Comments
Mehdi Gholam 18-Nov-11 3:53am    
You don't need to join when you already have the username and it is in the user table.
Reiss 18-Nov-11 4:47am    
True, but why make two calls to the database when you can do it in one - to me the title suggests that this is what the user is doing
SQL
select type from user where username = @username


@username is a parameter that you have to pass it to stored procedure or sql statement.
 
Share this answer
 
v2
better to use identity column in Admin table and make it primary key .
In the User table take a friegn key (eg.UserId)then try the following query :
SQL
select type from UserT inner join Admin on  UserT.UserId=Admin.UserId
 where UserT.UserName='xyz'
 
Share this answer
 
v3
SQL
SELECT type FROM Admin a
INNER JOIN User u ON a.username = u.username
WHERE
    a.username = @username
AND
    a.password = @password
 
Share this answer
 
SQL
select type from user u, admin a where a.username=b.username and a.username='demo' and a.password='demo'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900