Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.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
Php 在同一行中选择distinct和other列_Php_Mysql - Fatal编程技术网

Php 在同一行中选择distinct和other列

Php 在同一行中选择distinct和other列,php,mysql,Php,Mysql,是否有一种简单的、非连接的方式来执行此任务 mysql_query("select DISTINCT artist, id from ringtones where artletter='A'"); 结果应该是:所有艺术家值都没有对应id的重复项。通过执行以下操作,您可以为每个艺术家获得一行,该艺术家的所有id都在一行上: SELECT artist, GROUP_CONCAT(id) as `IDs` FROM ringtones WHERE artletter='A' GROUP BY a

是否有一种简单的、非连接的方式来执行此任务

mysql_query("select DISTINCT artist, id from ringtones where artletter='A'");

结果应该是:所有艺术家值都没有对应id的重复项。

通过执行以下操作,您可以为每个艺术家获得一行,该艺术家的所有id都在一行上:

SELECT artist, GROUP_CONCAT(id) as `IDs`
FROM ringtones
WHERE artletter='A'
GROUP BY artist;
如果您只需要每个艺术家的第一个
id
,请尝试以下操作:

SELECT artist, MIN(id) as `first_id`
FROM ringtones
WHERE artletter='A'
GROUP BY artist;
(您可以使用
MAX
而不是
MIN
来获取最后一个
id


如果您想要该艺术家的第一行或最后一行(基于
id
),您可以按照该链接中的描述执行。通过执行以下操作,您可以为每个艺术家获得一行,该艺术家的所有id位于一行:

SELECT artist, GROUP_CONCAT(id) as `IDs`
FROM ringtones
WHERE artletter='A'
GROUP BY artist;
如果您只需要每个艺术家的第一个
id
,请尝试以下操作:

SELECT artist, MIN(id) as `first_id`
FROM ringtones
WHERE artletter='A'
GROUP BY artist;
(您可以使用
MAX
而不是
MIN
来获取最后一个
id


如果您想要该艺术家的第一行或最后一行(基于
id
),您可以按照该链接中的描述进行编辑。

您可能正在查找此

select DISTINCT artist, id where id IN(select DISTINCT id from ringtones where artletter='A')

也许你在找这个

select DISTINCT artist, id where id IN(select DISTINCT id from ringtones where artletter='A')

你得到了什么?您希望得到什么?在这个查询中是否有任何联接???提供更多信息,表结构会有所帮助。具体应该选择什么?您是否尝试过使用“艺术家分组”?这将消除所有重复项…但也只会给你它找到的第一个ID。你得到了什么?您希望得到什么?在这个查询中是否有任何联接???提供更多信息,表结构会有所帮助。具体应该选择什么?您是否尝试过使用“艺术家分组”?这将消除所有的重复…但也只给你它找到的第一个ID。第一个应该是你需要的第二个正是我需要的。谢谢杰里米第一个应该是你需要的第二个正是我需要的。谢谢Jeremy=)