SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 simple join query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vignesht50
Yak Posting Veteran

76 Posts

Posted - 11/26/2013 :  06:07:45  Show Profile  Reply with Quote
CREATE TABLE PROFILES(
ID varchar(20) UNIQUE NOT NULL,
Name varchar(40) NULL,
Address varchar(25) NULL
)

insert into PROFILES values ('rryan','Jamie Fox','jfox@live.com')
insert into PROFILES values ('mclark','Michael Clark','mclark@live.com')
insert into PROFILES values ('djones','Dean Jones','djones@live.com')
insert into PROFILES values ('jfox','Jamie Fox','jfox@live.com')
insert into PROFILES values ('drivers','Doc Rivers','drivers@live.com')


CREATE TABLE ROLE(
ID varchar(20) UNIQUE NOT NULL,
Role char(10) NOT NULL,
Applications char (10) NOT NULL
)

insert into ROLE values ('rryan','M','Consultant')
insert into ROLE values ('mclark','AM','Organizer')
insert into ROLE values ('djones','SM','Admin')
insert into ROLE values ('jfox','M','Consultant')
insert into ROLE values ('drivers','AM','Organizer')

I am trying to join two tables and my expected output is

EXPECTED OUTPUT
ID Name Address Role Application

This is my query and I am not able to join

SELECT ID, Name, Address, Role, Applications
from PROFILES
RIGHT JOIN ROLE
ON PROFILES.ID = ROLE.ID

Can anyone correct me?

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 11/26/2013 :  06:34:48  Show Profile  Reply with Quote

SELECT p.ID, Name, Address, Role, Applications
FROM PROFILES p
INNER JOIN ROLE r
ON p.ID = r.ID


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Prav4u
Starting Member

India
15 Posts

Posted - 11/26/2013 :  06:36:46  Show Profile  Reply with Quote
Hi,
try this

SELECT PROFILES.ID, Name, Address, Role, Applications
from PROFILES
LEFT JOIN ROLE
ON PROFILES.ID = ROLE.ID

Praveen D'sa
MCITP - Database Administrator 2008
http://sqlerrors.wordpress.com
Go to Top of Page

vignesht50
Yak Posting Veteran

76 Posts

Posted - 11/26/2013 :  06:45:15  Show Profile  Reply with Quote
Should have mentioned table name, got ambiguity problem. Thanks and got it solved.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 11/26/2013 :  06:45:22  Show Profile  Reply with Quote
Doesnt require LEFT JOIN unless you've profiles without any assigned roles.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000