M
M
maryxoxoxo2020-01-15 11:58:08
SQL
maryxoxoxo, 2020-01-15 11:58:08

How to correctly set the SQL script?

Two tables:

<i>1. equipment </i>
id_eq Первичный	int(11)
name	varchar(120)
sn	varchar(25)	
invn	varchar(14)
type_eq	varchar(25)
location	varchar(25)
note1	varchar(120)

<i>2. moving_eq2</i>
id_mov Первичный	int(11)
name_eq	varchar(120)
id_eq	int(11)
datetime	date	
fio1	varchar(50)
fio2	varchar(50)
fioIT	varchar(50)
note

What is the correct way to set a sql query to output everything from the equipment table where all elements of moving_eq2.id_eq are excluded? moving_eq2.id_eq is a foreign key.
Tried like this:
SELECT name, sn, invn, type_eq, location, note1  
    FROM equipment AS t1
    WHERE id_eq NOT IN 
        	(SELECT * FROM moving_eq2 AS t2 
            WHERE t1.id_eq = t2.id_eq)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2020-01-15
@maryxoxoxo

SELECT name, sn, invn, type_eq, location, note1
  FROM equipment
    LEFT JOIN moving_eq2 ON moving_eq2.id_eq = equipment.id_eq
  WHERE moving_eq2.id_eq IS NULL

SQL JOIN
VQ5XP.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question