Вопрос

I know some of SQL but, I always use join, left, cross and so on, but in a query where the tables are separated by a comma. It's looks like a cross join to me. But I don't know how to test it (the result is the same with the tries I made).

SELECT A.id, B.id
FROM A,B
WHERE A.id_B = B.id

Even in the great Question (with great answers) "What is the difference between Left, Right, Outer and Inner Joins?" I didn't find an answer to this.

Это было полезно?

Решение

It would be a cross join if there wasn't a WHERE clause relating the two tables. In this case it's functionally equivalent to an inner join (matching records by id_rel and id)

It's an older syntax for joining tables that is still supported in most systems, but JOIN syntax is largely preferred.

Другие советы

This is old pre - 1992 standard SQL join syntax, which you should not mimic or use in anything you write today

The where clause specifies the join style and columns. You can use = or *= or=* in the where to make join, left or right joins. No joins in the WHERE make it a cross join.

As long as you have join criteria provided in the where clause, this syntax results in an inner join. For example:

Where tableA.value = TableB.Value

Looks to me like an INNER JOIN

i.e. both sides must exist to get a result.

For example:

SELECT 
  A.id, B.id
FROM A
  INNER JOIN B ON A A.id_rel = B.id
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top