user3553846
user3553846

Reputation: 342

SELECT clause with condition

Help me explain what is this question meant.

"Find all combination of employee names and department names."

For my table

//EMPLOYEE 
E#       ENAME       DNAME
-----------------------------
1         JOHN         IT
2         MAY         SCIENCE
3         SITI        SCIENCE

//DEPARTMENT
DNAME
------------
RESEARCH
   IT
 SCIENCE

just for my understanding. what is the question want me to do? i used the following query

SELECT ENAME,DNAME FROM EMPLOYEE;

Upvotes: 0

Views: 54

Answers (3)

crthompson
crthompson

Reputation: 15875

Its a bit unclear, but to find all combinations you would create a Cartesian product.

select
  e.ename, d.dname
from
  employee e,
  dname d

Oracle supports the above sql and uses CROSS JOIN as well to mean the same thing.

select
  e.ename, d.dname
from
  employee e cross join dname d

This joins each row in the employee table to each other row in the dname table.

This would create:

ENAME       DNAME
---------------------
JOHN         IT
JOHN         SCIENCE
JOHN         RESEARCH
MAY         SCIENCE
MAY         RESEARCH
MAY         IT
SITI        SCIENCE
SITI        IT
SITI        RESEARCH

Upvotes: 1

ashishmaurya
ashishmaurya

Reputation: 1196

this should work

select employee.ENAME,department.DNAME from employee,department

Upvotes: 0

sion_corn
sion_corn

Reputation: 3151

My understanding is they want you to create a cartesian:

select 
    EMPLOYEE.ENAME
    ,DEPARTMENT.DNAME
FROM EMPLOYEE, DEPARTMENT

Upvotes: 0

Related Questions