S
S
Silver16162019-11-20 21:25:00
MySQL
Silver1616, 2019-11-20 21:25:00

How to properly join SQL tables?

there is a NAME table
5dd58486ca596379337256.png
there is a PRIC table
5dd584c842e15307963501.png
Help me write a query that displays the following information from the NAME and PRIC tables:
Employee name; The address; Salary
But if the salary for one of the employees is not specified, then in the resulting selection in the Salary field, you must specify 0.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
irishmann, 2019-11-20
@Silver1616

SELECT
    n.`Name`,
    n.`Address`,
    CASE 
        WHEN p.`Zarp` IS NULL THEN 0
        ELSE p.`Zarp`
    END as `Zarp`
FROM `NAME` n
LEFT JOIN `PRIC` p ON n.`Name` = p.`Name`

PS: Not the best solution to bind by varchar. The connection will be many to many, and duplicates will fall. Deliver the identifier to the first table by primary key, and in the second secondary and on them JOIN, communication will be one to one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question