Answer the question
In order to leave comments, you need to log in
SQL query selection from 2 tables?
Hello good people!
I have a question of abstract content, I haven’t touched SQL for a long time, but they asked me a question, I answered it and now I smell what they thought of me.
For example, there are 2 tables:
1Table
id , name
2Table
worker_id, date, value You
need to select workers who did not receive a salary in the specified month / date.
Actually what I replied:
SELECT id name FROM table1 LEFT JOIN b as (SELECT worker_id date value FROM table2 WHERE data = 'интересующая дата' ) ON table1.id = b.worker_id WHERE date = 'null'
Answer the question
In order to leave comments, you need to log in
First - always format the code, and it's easier for you, and there are fewer errors, and it's nice for people to look ...
SELECT id name // выполнится, но не так как задумано, не хватает запятых
FROM table1
LEFT JOIN b as // здесь все совсем плохо
(
SELECT worker_id date value //тут уже даже не выполнится
FROM table2
WHERE data = 'интересующая дата' //date же!
)
ON table1.id = b.worker_id //могло бы даже работать, но выше куча ошибок
WHERE date = 'null' // так работать не будет. date IS NULL будет, но у вас вроде нужно value проверять?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question