Answer the question
In order to leave comments, you need to log in
How to get all sorts of unique pairs of two fields from one table?
There is such a table:
create table EMPLOYEE(
PK_ID int identity(1,1) NOT NULL,
DEPARTMENT_ID int NOT NULL,
FK_CHIEF_ID int NOT NULL,
NAME varchar(255) NOT NULL,
POSITION varchar(255) NOT NULL,
SALARY float NOT NULL,
constraint PK_ID_ID primary key (PK_ID),
constraint FK_CHIEF_ID_EMPLOYEE foreign key (FK_CHIEF_ID) references EMPLOYEE (PK_ID),
)
INSERT INTO EMPLOYEE VALUES
(2, 1, 'NAT','programmer',145.9),
(2, 1, 'IVA','programmer',200.1),
(2, 1, 'EVG','boss',300.0),
(2, 1, 'TAN','artist',179.9),
(2, 1, 'NAT','teacher',222.9),
(2, 1, 'IVA','math',213.1),
(2, 1, 'NAT','sport',151.9),
(2, 1, 'IVA','math',134.1),
(3, 1, 'EVG','boss',142.0),
(3, 1, 'NAT','actor',167.9),
(3, 1, 'EVG','boss',333.0),
(4, 1, 'TAN','language',543.9),
(4, 1, 'IVA','math',654.1),
(4, 1, 'TAN','artist',465.9),
(4, 1, 'TAN','programmer',789.9);
Answer the question
In order to leave comments, you need to log in
If you mean those pairs that are not in the table, then this is through CROSS JOIN:
SELECT DISTINCT a.name, b.position
FROM (SELECT name FROM employee) AS a CROSS JOIN (SELECT position FROM employee) AS b;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question