Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opposite of INNER JOIN with EXIST requirement

Tags:

mysql

If inner join requires that a row exists, what's the opposite of it without having to do a sub query of NOT EXISTS?

I replaced

 AND NOT EXISTS (
  SELECT
   *
  FROM topic_read_assoc
  WHERE topic_id = topic.id
   AND member_id = ".$this->tru->application->currentMember->getId()."
 )

with

OUTER JOIN topic_read_assoc ON (
 topic_read_assoc.topic_id = topic.id AND
 member_id = member_id = ".$this->tru->application->currentMember->getId()."
)

and it's not producing the same results as the first query (which works)

like image 796
Webnet Avatar asked Nov 14 '10 06:11

Webnet


People also ask

What's the opposite of an inner join?

If you consider an inner join as the rows of two tables that meet a certain condition, then the opposite would be the rows in either table that don't.

What happens if you use inner join with no conditions?

When using join or inner join , the on condition is optional. This is different from the ANSI standard and different from almost any other database. The effect is a cross join . Similarly, you can use an on clause with cross join , which also differs from standard SQL.

What is the difference between inner join and exists?

Generally speaking, INNER JOIN and EXISTS are different things. The former returns duplicates and columns from both tables, the latter returns one record and, being a predicate, returns records from only one table. If you do an inner join on a UNIQUE column, they exhibit same performance.

How do you replace not exists with a join?

select distinct a.id, a.name from Employee a join Dependencies b on a.id = b. eid where not exists ( select * from Dependencies d where b.id = d.id and d.name = 'Apple' ) and exists ( select * from Dependencies c where b.id = c.id and c.name = 'Orange' );


1 Answers

OUTER JOIN with a WHERE field IS NULL

Example:

SELECT A.name FROM A INNER JOIN B on A.id = B.id

Select those names in A whose id fields exist in B

Opposite:

SELECT A.name FROM A OUTER JOIN B on A.id = B.id WHERE B.id IS NULL

Select those names in A whose id fields do not exist in B

like image 66
Aishwar Avatar answered Oct 07 '22 22:10

Aishwar