V
V
Viktor Taran2020-09-16 13:13:01
SQL
Viktor Taran, 2020-09-16 13:13:01

How to add a join with two conditions to a past join?

SELECT
    *
FROM
    `betaintranet`.`ad_stat_cleaned`
LEFT JOIN `ad_c`  ON ad_stat_cleaned.bid = ad_c.bid
LEFT JOIN `total` ON ad_c.ban_type = ad_c.ban_type and  ad_c.w_site = ad_c.w_site
WHERE
    `date` = '2020-09-09'

1 I connect the second plate by bid and get the data I need. Everything is ok here.
Next, I need to connect another plate, but not by bid , but it has ban_type and w_site
in the second join, I need to connect only total
According to the following criterion, w_site matched and ban_type matched.
but I'm doing something wrong, it's obvious.

ad_stat_cleaned
(`bid`, `date`, `shows`, `clicks`, `modification`)

ad_c
(`cid`, `ad_name`, `bid`, `ban_type`, `obj_id`, `ra_id`, `dev_id`, `w_site`, `m_invoice`, `start_date`, `end_date`, `stopflag`, `zaglusha`, `phone`, `dyn_number`, `whocreated`, `time_created`, `whoedited`, `time_edited`) VALUES

total
(`ID`, `ban_type`, `w_site`, `total`, `descryption`)


5f61e5d89f743199739643.png
I need to add only total to the table

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-09-16
@shambler81

Why are you comparing the string to itself?
ON ad_c .ban_type = ad_c .ban_type and ad_c .w_site = ad_c .w_site

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question