MySql,如何在3列

时间:2018-02-04 10:16:56

标签: mysql

我已尝试按col1,col2,col3分组,但不起作用,因为3列的所有值都不能重复,不能与其他值相等。

表格代表:

+--------+--------+--------+
| col1   | col2   | col3   |
+--------+--------+--------+
| value1 | value3 | value5 |
+--------+--------+--------+
| value1 | value2 | value1 |
+--------+--------+--------+
| value3 | value1 | value3 |
+--------+--------+--------+

我需要选择不重复的值

该表有100多万行,构建查询时性能很重要

非常感谢你!

2 个答案:

答案 0 :(得分:1)

(select distinct col1 from table) UNION DISTINCT (select distinct col2 from table) UNION DISTINCT (select distinct col1 from table)

答案 1 :(得分:1)

我能够使用非重复值构建查询。

.dropdown {
  position: absolute;
  display: inline-block;
  z-index: 1;
  top: 25px;
}

.dropbtn {
  background-color: #4CAF50;
  color: white;
  padding: 15px;
  font-size: 20px;
  border-radius: 0 5px 5px 0;
  border: none;
  transition: 0.4s;
}

.dropdown-content {
  display: none;
  background-color: #4CAF50;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
  border-radius: 0 5px 5px 0;
}

.dropdown:hover {
  left: 20px;
}

.dropdown-content a {
  color: white;
  padding: 12px 16px;
  text-decoration: none;
  display: inline-block;
}

.dropdown:hover .dropdown-content {
  display: inline-grid;
}