从所有结果中获取一个结果 - MySQL

时间:2022-09-22 15:12:14

Here is an example table to start out with, so you understand what I'm trying to do:

这是一个开始的示例表,因此您了解我正在尝试做什么:

 id  | name   | topic
-----|--------|-------
 1   | jake   | php
 2   | jared  | html
 3   | clay   | css
 4   | jake   | html
 5   | jay    | html
 5   | jay    | php

How do I get that there is only php, html, and css isntead of having it say
php, html, css, html, html, php instead I want php, html, css

我如何得到只有php,html和css而不是让它说php,html,css,html,html,php而不是我想要php,html,css

Is there some sort of SQL / MySQL command to do this?

是否有某种SQL / MySQL命令来执行此操作?

2 个解决方案

#1


0  

SELECT DISTINCT topic FROM your_table;

从your_table中选择DISTINCT主题;

DISTINCT means to return "distinct" rows; ie: rows that don't match another row already being returned.

DISTINCT意味着返回“不同”行;即:与已返回的另一行不匹配的行。

#2


0  

SELECT * FROM your_table ORDER BY topic

SELECT * FROM your_table ORDER BY主题

#1


0  

SELECT DISTINCT topic FROM your_table;

从your_table中选择DISTINCT主题;

DISTINCT means to return "distinct" rows; ie: rows that don't match another row already being returned.

DISTINCT意味着返回“不同”行;即:与已返回的另一行不匹配的行。

#2


0  

SELECT * FROM your_table ORDER BY topic

SELECT * FROM your_table ORDER BY主题