R
R
Roman Govorov2020-07-02 12:44:01
SQL
Roman Govorov, 2020-07-02 12:44:01

How to find the number of rows in a SQL query with JOIN?

The request is the following:

SELECT leads.*, sites.NAME_SITE
        FROM `leads` leads 
        LEFT JOIN `sites` sites ON sites.SOURCE_ID = leads.SOURCE_ID 
            WHERE 
            leads.PHONE != "9 (999) 999 99-99" AND 
            leads.NAME != "тест" AND 
            leads.SOURCE_ID IN (1,3,4,5,6,7,8,10,11,12,14,15) AND 
            `DATE_CREATE` BETWEEN "2020-06-01" AND "2020-06-30" 
            GROUP BY leads.PHONE ORDER BY DATE_CREATE DESC

It is necessary to return a value of 600 rows, I know that you can do this with COUNT (*), but I can’t figure out how to cram it into this query ...
5efdad15a4796172158411.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-07-02
@RGameShow

SELECT COUNT(DISTINCT `leads`.`PHONE`)
  FROM `leads`
  LEFT JOIN `sites` ON `sites`.`SOURCE_ID` = `leads`.`SOURCE_ID`
  WHERE `leads`.`PHONE` != '9 (999) 999 99-99'
    AND `leads`.`NAME` != 'тест'
    AND `leads`.`SOURCE_ID` IN (1,3,4,5,6,7,8,10,11,12,14,15)
    AND `DATE_CREATE` BETWEEN '2020-06-01' AND '2020-06-30'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question