## Forum Stats

• 3,723,920 Users
• 2,244,650 Discussions

Discussions

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# how does the where clause work here?

Member Posts: 1

SELECT ename, e.deptno, dname, loc

FROM emp e, dept d

WHERE e.deptno > d.deptno;

Tagged:

• Member Posts: 8,193 Gold Crown

No idea why you would do this on emp and dept, but this is called a non-equijoin. A non-equijoin is a join which matches column values from different tables based on an inequality expression (instead of the usual equal sign). So something like >, <, >=, <=.

The value of the join column in each row in the source table is compared to the corresponding values in the target table. A match is found if the expression based on an inequality operator used in the join, evaluates to true. So in your case, it evaluates to true for all cases where the emp.deptno is greater than a department no in the dept table. When it's true, it returns the values from the tables you specified.

• Member, Moderator Posts: 40,207 Red Diamond

Hi,

If you didn't have the join condition

```SELECT ename, e.deptno, dname, loc
FROM emp e, dept d
-- WHERE e.deptno > d.deptno
;
```

then the results would contain all possible combinations. Every row in table e would be joined to every row in table d.

Including the join condition means you only get a sub-set of those output rows. The only rows included will be the rows where the condition

```WHERE e.deptno > d.deptno
```

is true.