- USE master;
- GO
- -- Create our first table variable to hold user accounts.
- DECLARE @UserAccounts TABLE
- (
- acountID INT
- , firstName VARCHAR(50)
- , lastName VARCHAR(50)
- );
- -- Create our second table variable to hold our user account passwords.
- DECLARE @Passwords TABLE
- (
- acountID INT
- , [password] VARCHAR(50)
- );
- -- Insert some records into our UserAccounts table variable.
- INSERT INTO @UserAccounts
- VALUES (1, 'John', 'Doe');
- INSERT INTO @UserAccounts
- VALUES (2, 'Jane', 'Doe');
- INSERT INTO @UserAccounts
- VALUES (3, 'Jim', 'Doe');
- -- Insert some records into our Passwords table variable.
- INSERT INTO @Passwords
- VALUES (1, 'password');
- INSERT INTO @Passwords
- VALUES (2, 'jane32');
- INSERT INTO @Passwords
- VALUES (3, 'Password!');
- -- Inner join between two table variables.
- SELECT U.firstName, U.lastName, P.[password]
- FROM @UserAccounts AS U
- INNER JOIN @Passwords AS P
- ON U.acountID = P.acountID;
The output of this query should be:
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
firstName lastName password
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
John Doe password
Jane Doe jane32
Jim Doe Password!
(3 row(s) affected)
No comments:
Post a Comment