|
-
Nov 12th, 2009, 11:33 AM
#1
Thread Starter
Hyperactive Member
SQL Join
Hi all,
Let's say I have two tables:
tblComputer
computername
description
tblUser
username
password
A computer can have multiple users.
A user can only have 1 computer.
How would a table look like if there were 3 users using 1 computer and I joined them?
Like this?
tblJoined
tblComputer.computername
tblComputer.description
tblUser.username
tblUser.password
tblUser.username
tblUser.password
tblUser.username
tblUser.password
-
Nov 12th, 2009, 11:35 AM
#2
Re: SQL Join
I think this would be better demonstrated with sample data.
How do you plan to join tblUser with tblComputer? I don't see a common key.
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Nov 12th, 2009, 12:28 PM
#3
New Member
Re: SQL Join
You will need to restructure your tables a little, like this:
tblComputer
tblComputerID (identity field, Primary Key)
computername
description
tblUser
tblComputerID (Foreign Key, related to tblComputer/tblComputerID)
username
password
The tblUser/tblComputerID points to which computer is associated with which user.
Then your SQL Statements will have to contain a JOIN on the key
Make sense?
Regards,
Will
-
Nov 12th, 2009, 02:26 PM
#4
Fanatic Member
Re: SQL Join
vb Code:
SELECT c.[Name],c.Description, u.UserName, u.PassWord FROM [User] u INNER JOIN Computer c on u.computerID = c.ID
Will produce a result set like so:
Name Description UName Password
Comp1 Development Machine JCG 1234
Comp1 Development Machine MPH aaabbb
Comp1 Development Machine DRH Zebra
Where I'm from we only have one bit of advice for new comers: "If you hear banjos, turn and run".
VS 2008 .NetFW 2.0
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|