通过在 mysql 查询中使用带有 distinct 子句的 where 子句,我们设置了一个条件,mysql 根据该条件返回结果集的唯一行。通过在 mysql 查询中使用 limit 子句和 distinct 子句,我们实际上向服务器提供了一个关于要返回的结果集的最大唯一行数的范围。
示例我们可以在名为“testing”的表上使用带有 distinct 的 where 和 limit 子句,如下所示 -
mysql> select * from testing;+------+---------+---------+| id | fname | lname |+------+---------+---------+| 200 | raman | kumar || 201 | sahil | bhalla || 202 | gaurav | null || 203 | aarav | null || 204 | harshit | khurana || 205 | rahul | null || 206 | piyush | kohli || 207 | lovkesh | null || 208 | gaurav | kumar || 209 | raman | kumar |+------+---------+---------+10 rows in set (0.00 sec)mysql> select distinct lname from testing where lname is not null limit 3;+---------+| lname |+---------+| kumar || bhalla || khurana |+---------+3 rows in set (0.00 sec)
以上就是我们如何将 mysql distinct 子句与 where 和 limit 子句一起使用?的详细内容。