Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Junction table select query

$
0
0

CREATE DATABASE ABC1_ORG

 USE ABC1_ORG


CREATE TABLE EMPLOYEE
(
E_ID numeric(10) NOT NULL,
E_Name varchar(20) NOT NULL,
E_City varchar(10),
E_Designayion varchar(20) NOT NULL

CONSTRAINT PK_Emp PRIMARY KEY(E_ID)
)

CREATE TABLE SKILLS
(
S_ID numeric(10) NOT NULL,
S_Name varchar(20) NOT NULL,

CONSTRAINT PK_SKILL PRIMARY KEY(S_ID)
)

CREATE TABLE EMP_SKILL
(
E_ID NUMERIC(10) NOT NULL,
S_ID NUMERIC(10),

CONSTRAINT PK_EMP_SKILL PRIMARY KEY(E_ID, S_ID),

CONSTRAINT EMP_SKILL_FK FOREIGN KEY (E_ID) REFERENCES   EMPLOYEE(E_ID),

CONSTRAINT SKILL_EMP_SKILL_FK FOREIGN KEY(S_ID) REFERENCES SKILLS(S_ID)
)


 INSERT INTO EMPLOYEE VALUES(1,'ali', 'Lahore','Manager') 
 INSERT INTO EMPLOYEE VALUES(2,'Zoahir','Islamabad','Manager') 
 INSERT INTO EMPLOYEE VALUES(3,'Arusa','Lahore','QA') 
 INSERT INTO EMPLOYEE VALUES(4,'Rehab','Lahore','Analyst') 
 INSERT INTO EMPLOYEE VALUES(5,'ali','Karachi','Manager') 

 INSERT INTO SKILLS VALUES (1,'B.A')
 INSERT INTO SKILLS VALUES (2,'MBA')
 INSERT INTO SKILLS VALUES (3,'BBA')
 INSERT INTO SKILLS VALUES (4,'CA')
 INSERT INTO SKILLS VALUES (5,'SQA')

 INSERT INTO EMP_SKILL(E_ID,S_ID) VALUES (1,1)
 INSERT INTO EMP_SKILL(E_ID,S_ID) VALUES (1,2)
 INSERT INTO EMP_SKILL(E_ID,S_ID) VALUES (1,3)

PROBLEM here: I am trying to display all the skills one customer have , but not working. Maybe. I don't know how to query this.


 select EMPLOYEE.E_ID, EMPLOYEE.E_Name, EMPLOYEE.E_Designayion, SKILLS.S_ID,SKILLS.S_Name
 from EMPLOYEE inner join SKILLS on EMPLOYEE.E_ID = SKILLS.S_ID


Asia


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>