F
F
fiter2017-11-24 21:15:24
css
fiter, 2017-11-24 21:15:24

How to make a mysql selection with the calculation of the number of unique values?

Unable to add unique c.catalog_id count to this query

$contacts = $dbh->prepare("
SELECT r.title AS region_title, 
c.title,
c.region_id, 
c.id, 
c.catalog_id, 
c.address, 
c.phone, 
c.email, 
c.website, 
c.category_title, 
c.subcategory_title, 
c.subcategory_id, 
c.manufacturer 
  FROM contacts AS c 
  LEFT 
  JOIN regions AS r 
    ON c.region_id = r.id 
 WHERE manufacturer = 1 
   AND region_id IN (".implode(',', $regions).") 
   AND subcategory_id IN (".implode(',', $categories).")
");
$contacts->execute();
$contacts->fetchAll(PDO::FETCH_GROUP);

ps contact list should be grouped by region_title:
array() {
  ["Хабаровск"]=>
  array() {
    contact1
    contact2
    ...
  },
  ["Чебоксары"]=>
  array() {
    contact3
    contact4
    ...
  }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lukoie, 2019-09-07
@lukoie

waited for loading seconds 20
closed nafik
don't make such a hover effect

D
Dimonchik, 2017-11-24
@dimonchik2013

count () as ct group by ... having ct > 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question