Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何使用select distinct查询获取id_Mysql - Fatal编程技术网

Mysql 如何使用select distinct查询获取id

Mysql 如何使用select distinct查询获取id,mysql,Mysql,我在mysql表中有: id |头衔|位置|价格 表中有重复项。为了得到我使用的所有独特的 选择不同的标题、位置、价格 是否可以仅使用sql查询获取所有唯一行的ID?无论哪个id将与行(第一行、第二行或最后一行)关联。 感谢您的帮助像这样使用 select distinct id, title, location from table_name 如果标题、位置、价格字段有重复记录 那么下面的查询将是最好的 select id from tablel1 group by title, locat

我在mysql表中有:

id |头衔|位置|价格

表中有重复项。为了得到我使用的所有独特的

选择不同的标题、位置、价格

是否可以仅使用sql查询获取所有唯一行的ID?无论哪个id将与行(第一行、第二行或最后一行)关联。 感谢您的帮助

像这样使用

select distinct id, title, location
from table_name

如果标题、位置、价格字段有重复记录

那么下面的查询将是最好的

select id from tablel1 group by title, location, price

一旦包含
id
,如果这些值不同,那么您就不能再依赖
DISTINCT
的默认行为。您需要定义您自己的逻辑“独特”的含义。从本质上讲,听起来你的数据不好。与其试图有效地忽略它,不如更正它。请参阅:请发布包含数据和预期输出的表Hanks,这有助于解释为什么我的答案是向下的,这是正确的答案,您可以测试我的查询我没有向下推。我还不能这样做。我认为你的回答是对的