# 面试官:谈谈你对mysql联合索引的认识？

(1)联合索引部分的基础知识

(2)联合索引部分的实战题

## 正文

### 基础

a = 1
a = 1 and b = 2

b= 2 and a =1

b = 2

a = 1 and b = 2 and c > 3 and d = 4

### 实战

OK，懂上面的基础，我们就可以开始扯了~我举了经典的五大题型，看完基本就懂！

#### 题型一

SELECT * FROM table WHERE a = 1 and b = 2 and c = 3;

#### 题型二

SELECT * FROM table WHERE a > 1 and b = 2;

#### 题型三

SELECT * FROM table WHERE a > 1 and b = 2 and c > 3;

SELECT * FROM table WHERE a = 1 and b = 2 and c > 3;

#### 题型四

SELECT * FROM table WHERE a = 1 ORDER BY b;

SELECT * FROM table WHERE a > 1 ORDER BY b;

SELECT * FROM table WHERE a = 1 AND b = 2 AND c > 3 ORDER BY c;

#### 题型五

SELECT * FROM table WHERE a IN (1,2,3) and b > 1;

SELECT * FROM table WHERE a = 1 AND b IN (1,2,3) AND c > 3 ORDER BY c;