select_found.result 1.17 KB
Newer Older
unknown's avatar
unknown committed
1 2 3 4
drop table if exists t1;
create table t1 (a int not null auto_increment, b int not null, primary key(a));
insert into t1 (b) values (2),(3),(5),(5),(5),(6),(7),(9);
select SQL_CALC_FOUND_ROWS * from t1;
5 6 7 8 9 10 11 12 13
a	b
1	2
2	3
3	5
4	5
5	5
6	6
7	7
8	9
unknown's avatar
unknown committed
14
select found_rows();
15 16
FOUND_ROWS()
8
unknown's avatar
unknown committed
17
select SQL_CALC_FOUND_ROWS * from t1 limit 1;
18 19
a	b
1	2
unknown's avatar
unknown committed
20
select found_rows();
21 22
FOUND_ROWS()
8
unknown's avatar
unknown committed
23
select SQL_CALC_FOUND_ROWS * from t1 order by b desc limit 1;
24 25
a	b
8	9
unknown's avatar
unknown committed
26
select found_rows();
27 28
FOUND_ROWS()
8
unknown's avatar
unknown committed
29
select SQL_CALC_FOUND_ROWS distinct b from t1 limit 1;
30 31
b
2
unknown's avatar
unknown committed
32
select found_rows();
33 34
FOUND_ROWS()
6
unknown's avatar
unknown committed
35
select SQL_CALC_FOUND_ROWS b,count(*) as c from t1 group by b order by c desc limit 1;
36
b	c
37
5	3
unknown's avatar
unknown committed
38
select found_rows();
39 40
FOUND_ROWS()
6
unknown's avatar
unknown committed
41
select SQL_CALC_FOUND_ROWS * from t1 left join t1 as t2 on (t1.b=t2.a) limit 2,1;
42 43
a	b	a	b
3	5	5	5
unknown's avatar
unknown committed
44
select found_rows();
45 46
FOUND_ROWS()
8
unknown's avatar
unknown committed
47
drop table t1;
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
create table t1 (a int not null primary key);
insert into t1 values (1),(2),(3),(4),(5);
select sql_calc_found_rows a from t1 where a in (1,2,3) order by a desc limit 0,2;
a
3
2
select FOUND_ROWS();
FOUND_ROWS()
3
select sql_calc_found_rows a from t1 where a in (1,2,3) order by a+2 desc limit 0,2;
a
3
2
select FOUND_ROWS();
FOUND_ROWS()
3
drop table t1;