SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 6th, 2004, 03:22 PM
Wee Bubs Wee Bubs is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 Wee Bubs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
is this sort of join possible?

i have 2 tables like this:

user table:

| user_id | forename | surname |
--------------------------------------
| 1 | john | smith |
| 2 | susan | jones |
| 3 | gary | walsh |
--------------------------------------
results table:

| user1 | user2 | score |
--------------------------------------
| 2 | 3 | 20 |
| 1 | 2 | 50 |
--------------------------------------

i need an sql which will give join forename and surname on both user1 and user 2 column

so results of joining line 1 of results would be:

user1_forename = susan;
user1_surname = jones;
user2_forename = gary;
user2_surname = walsh;
score = 20;

ive been trying something like this:

select u.forename as user1_forename,u.surname as user1_surname,
user2_forename,u.surname as user2_surname
from results r
inner join users u
on r.user1 = u.user_id
and r.user2 = u.user_id
...

but not working. is this possible & if not what can i do please!

Reply With Quote
  #2  
Old April 6th, 2004, 06:21 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
Try This

SELECT [User].[forename] AS User1_forename, [User].[surname] AS User1_surname, User2.forename AS User2_forename, User2.surname AS USer2_surname, [Results].[Score]
FROM [User] AS User2 INNER JOIN ([User] INNER JOIN Results ON [User].[user_id]=[Results].[user1]) ON User2.user_id=[Results].[user2];


S-

Reply With Quote
  #3  
Old April 6th, 2004, 06:44 PM
HWDave HWDave is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Long Beach, CA
Posts: 54 HWDave User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 15 m 52 sec
Reputation Power: 5
Talking

Quote:
Originally Posted by Wee Bubs
select u.forename as user1_forename,u.surname as user1_surname,
user2_forename,u.surname as user2_surname
from results r
inner join users u
on r.user1 = u.user_id
and r.user2 = u.user_id
I changed some of your variable names (fname instead of forename, lname instead of surname).
tables are z_score (your results table) and z_user (your users table).
Try this:
Code:
 SELECT	 z_score.uid1, z_score.uid2, z_user.fname, z_user.lname, z_score.score
FROM		 z_user INNER JOIN
					  z_score ON z_user.uid = z_score.uid1 OR z_user.uid = z_score.uid2
ORDER BY z_score.score 

If you order by z_score.score, it will parse the data in groups so they are used one at a time.
Your output will be:
Code:
   2 3 susan jones 20
 2 3 gary walsh 20
 1 2 john smith 50
 1 2 susan jones 50

To just get names simply drop uid1 & uid2 out of the select statement. Hope this helps!

Reply With Quote
  #4  
Old April 7th, 2004, 04:07 AM
Wee Bubs Wee Bubs is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 Wee Bubs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
aha! i was almost there. (well...sort of... )


many thanks for your expert help

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > is this sort of join possible?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT