Using DISTINCT and COUNT together in a MySQL Query

前端 未结 7 913
旧巷少年郎
旧巷少年郎 2020-11-30 22:04

Is something like this possible:

SELECT DISTINCT COUNT(productId) WHERE keyword=\'$keyword\'

What I want is to get the number of unique pro

7条回答
  •  情歌与酒
    2020-11-30 22:35

    FYI, this is probably faster,

    SELECT count(1) FROM (SELECT distinct productId WHERE keyword = '$keyword') temp
    

    than this,

    SELECT COUNT(DISTINCT productId) WHERE keyword='$keyword'
    

提交回复
热议问题