2002-05-16 15:06:57 +02:00
|
|
|
drop table if exists t1,t2;
|
2001-09-28 07:05:54 +02:00
|
|
|
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;
|
2001-05-23 01:40:46 +02:00
|
|
|
a b
|
|
|
|
1 2
|
|
|
|
2 3
|
|
|
|
3 5
|
|
|
|
4 5
|
|
|
|
5 5
|
|
|
|
6 6
|
|
|
|
7 7
|
|
|
|
8 9
|
2001-09-28 07:05:54 +02:00
|
|
|
select found_rows();
|
2003-01-28 00:55:41 +01:00
|
|
|
found_rows()
|
2001-05-23 01:40:46 +02:00
|
|
|
8
|
2001-09-28 07:05:54 +02:00
|
|
|
select SQL_CALC_FOUND_ROWS * from t1 limit 1;
|
2001-05-23 01:40:46 +02:00
|
|
|
a b
|
|
|
|
1 2
|
2001-09-28 07:05:54 +02:00
|
|
|
select found_rows();
|
2003-01-28 00:55:41 +01:00
|
|
|
found_rows()
|
2001-05-23 01:40:46 +02:00
|
|
|
8
|
2002-03-05 13:22:32 +01:00
|
|
|
select SQL_BUFFER_RESULT SQL_CALC_FOUND_ROWS * from t1 limit 1;
|
|
|
|
a b
|
|
|
|
1 2
|
|
|
|
select found_rows();
|
2003-01-28 00:55:41 +01:00
|
|
|
found_rows()
|
2002-03-05 13:22:32 +01:00
|
|
|
8
|
2001-09-28 07:05:54 +02:00
|
|
|
select SQL_CALC_FOUND_ROWS * from t1 order by b desc limit 1;
|
2001-05-23 01:40:46 +02:00
|
|
|
a b
|
|
|
|
8 9
|
2001-09-28 07:05:54 +02:00
|
|
|
select found_rows();
|
2003-01-28 00:55:41 +01:00
|
|
|
found_rows()
|
2001-05-23 01:40:46 +02:00
|
|
|
8
|
2001-09-28 07:05:54 +02:00
|
|
|
select SQL_CALC_FOUND_ROWS distinct b from t1 limit 1;
|
2001-05-23 01:40:46 +02:00
|
|
|
b
|
|
|
|
2
|
2001-09-28 07:05:54 +02:00
|
|
|
select found_rows();
|
2003-01-28 00:55:41 +01:00
|
|
|
found_rows()
|
2001-05-23 01:40:46 +02:00
|
|
|
6
|
2001-09-28 07:05:54 +02:00
|
|
|
select SQL_CALC_FOUND_ROWS b,count(*) as c from t1 group by b order by c desc limit 1;
|
2001-05-23 01:40:46 +02:00
|
|
|
b c
|
2001-06-25 10:35:22 +02:00
|
|
|
5 3
|
2001-09-28 07:05:54 +02:00
|
|
|
select found_rows();
|
2003-01-28 00:55:41 +01:00
|
|
|
found_rows()
|
2001-05-23 01:40:46 +02:00
|
|
|
6
|
2001-09-28 07:05:54 +02:00
|
|
|
select SQL_CALC_FOUND_ROWS * from t1 left join t1 as t2 on (t1.b=t2.a) limit 2,1;
|
2001-05-23 01:40:46 +02:00
|
|
|
a b a b
|
|
|
|
3 5 5 5
|
2001-09-28 07:05:54 +02:00
|
|
|
select found_rows();
|
2003-01-28 00:55:41 +01:00
|
|
|
found_rows()
|
2001-05-23 01:40:46 +02:00
|
|
|
8
|
2001-09-28 07:05:54 +02:00
|
|
|
drop table t1;
|
2002-02-08 02:21:34 +01:00
|
|
|
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()
|
2002-06-10 12:33:25 +02:00
|
|
|
3
|
2002-02-08 02:21:34 +01:00
|
|
|
drop table t1;
|
2002-05-16 15:06:57 +02:00
|
|
|
CREATE TABLE t1 (
|
|
|
|
`id` smallint(5) unsigned NOT NULL auto_increment,
|
|
|
|
`kid` smallint(5) unsigned NOT NULL default '0',
|
|
|
|
PRIMARY KEY (`id`),
|
|
|
|
KEY `kid` (`kid`)
|
|
|
|
);
|
|
|
|
CREATE TABLE t2 (
|
|
|
|
id smallint(5) unsigned NOT NULL auto_increment,
|
|
|
|
name varchar(50) NOT NULL default '',
|
|
|
|
email varchar(50) NOT NULL default '',
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
UNIQUE KEY e_n (email,name)
|
|
|
|
);
|
2004-08-07 23:18:13 +02:00
|
|
|
EXPLAIN SELECT SQL_CALC_FOUND_ROWS DISTINCT email FROM t2 LEFT JOIN t1 ON kid = t2.id WHERE t1.id IS NULL LIMIT 10;
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 SIMPLE t1 system PRIMARY,kid NULL NULL NULL 0 const row not found
|
2007-08-02 21:45:56 +02:00
|
|
|
1 SIMPLE t2 index NULL e_n 104 NULL 10
|
2002-05-16 15:06:57 +02:00
|
|
|
SELECT SQL_CALC_FOUND_ROWS DISTINCT email FROM t2 LEFT JOIN t1 ON kid = t2.id WHERE t1.id IS NULL LIMIT 10;
|
|
|
|
email
|
|
|
|
email1
|
|
|
|
email10
|
|
|
|
email100
|
|
|
|
email101
|
|
|
|
email102
|
|
|
|
email103
|
|
|
|
email104
|
|
|
|
email105
|
|
|
|
email106
|
|
|
|
email107
|
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
200
|
|
|
|
SELECT SQL_CALC_FOUND_ROWS DISTINCT email FROM t2 LEFT JOIN t1 ON kid = t2.id WHERE t1.id IS NULL order by email LIMIT 10;
|
|
|
|
email
|
|
|
|
email1
|
|
|
|
email10
|
|
|
|
email100
|
|
|
|
email101
|
|
|
|
email102
|
|
|
|
email103
|
|
|
|
email104
|
|
|
|
email105
|
|
|
|
email106
|
|
|
|
email107
|
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
200
|
|
|
|
SELECT DISTINCT email FROM t2 LEFT JOIN t1 ON kid = t2.id WHERE t1.id IS NULL LIMIT 10;
|
|
|
|
email
|
|
|
|
email1
|
|
|
|
email2
|
|
|
|
email3
|
|
|
|
email4
|
|
|
|
email5
|
|
|
|
email6
|
|
|
|
email7
|
|
|
|
email8
|
|
|
|
email9
|
|
|
|
email10
|
|
|
|
SELECT DISTINCT email FROM t2 LEFT JOIN t1 ON kid = t2.id WHERE t1.id IS NULL ORDER BY email LIMIT 10;
|
|
|
|
email
|
|
|
|
email1
|
|
|
|
email10
|
|
|
|
email100
|
|
|
|
email101
|
|
|
|
email102
|
|
|
|
email103
|
|
|
|
email104
|
|
|
|
email105
|
|
|
|
email106
|
|
|
|
email107
|
2003-10-11 22:26:39 +02:00
|
|
|
INSERT INTO `t1` (`id`, `kid`) VALUES ('0', '150');
|
2002-05-16 15:06:57 +02:00
|
|
|
SELECT SQL_CALC_FOUND_ROWS DISTINCT email FROM t2 LEFT JOIN t1 ON kid = t2.id WHERE t1.id IS NULL LIMIT 10;
|
|
|
|
email
|
|
|
|
email1
|
|
|
|
email2
|
|
|
|
email3
|
|
|
|
email4
|
|
|
|
email5
|
|
|
|
email6
|
|
|
|
email7
|
|
|
|
email8
|
|
|
|
email9
|
|
|
|
email10
|
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
199
|
|
|
|
drop table t1,t2;
|
2002-06-10 12:33:25 +02:00
|
|
|
CREATE TABLE `t1` (
|
|
|
|
`titre` char(80) NOT NULL default '',
|
|
|
|
`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
|
|
|
|
`maxnumrep` int(10) unsigned NOT NULL default '0',
|
|
|
|
PRIMARY KEY (`numeropost`),
|
|
|
|
KEY `maxnumrep` (`maxnumrep`)
|
2003-12-10 05:31:42 +01:00
|
|
|
) ENGINE=MyISAM ROW_FORMAT=FIXED;
|
2002-06-10 12:33:25 +02:00
|
|
|
INSERT INTO t1 (titre,maxnumrep) VALUES
|
|
|
|
('test1','1'),('test2','2'),('test3','3');
|
|
|
|
SELECT SQL_CALC_FOUND_ROWS titre,numeropost,maxnumrep FROM t1 WHERE numeropost IN (1,2) ORDER BY maxnumrep DESC LIMIT 0, 1;
|
|
|
|
titre numeropost maxnumrep
|
|
|
|
test2 2 2
|
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
2
|
2002-11-28 18:19:21 +01:00
|
|
|
SELECT SQL_CALC_FOUND_ROWS 1 FROM (SELECT 1) as a LIMIT 0;
|
2002-11-16 15:41:29 +01:00
|
|
|
1
|
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
1
|
2002-11-18 17:28:51 +01:00
|
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE numeropost > 1 LIMIT 0;
|
2002-11-16 15:41:29 +01:00
|
|
|
titre numeropost maxnumrep
|
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
2002-11-18 17:28:51 +01:00
|
|
|
2
|
2002-11-19 16:20:57 +01:00
|
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 0;
|
|
|
|
titre numeropost maxnumrep
|
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
3
|
2002-11-19 18:43:45 +01:00
|
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 ORDER BY numeropost LIMIT 0;
|
|
|
|
titre numeropost maxnumrep
|
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
3
|
2002-06-10 12:33:25 +02:00
|
|
|
drop table t1;
|
2003-12-11 05:24:08 +01:00
|
|
|
create table t1 (id int, primary key (id));
|
|
|
|
insert into t1 values (1), (2), (3), (4), (5);
|
|
|
|
select SQL_CALC_FOUND_ROWS * from t1 where id > 3 limit 0, 1;
|
|
|
|
id
|
|
|
|
4
|
|
|
|
select FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
2
|
|
|
|
select SQL_CALC_FOUND_ROWS * from t1 where id > 3 AND 1=2 limit 0, 1;
|
|
|
|
id
|
|
|
|
select FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
0
|
|
|
|
select SQL_CALC_FOUND_ROWS * from t1 where id > 6 limit 0, 1;
|
|
|
|
id
|
|
|
|
select FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
0
|
|
|
|
drop table t1;
|
2004-02-12 20:45:39 +01:00
|
|
|
CREATE TABLE t1 ( a int not null, b int not null, KEY ab(a,b) );
|
|
|
|
INSERT INTO t1 VALUES ( 47, 1 );
|
|
|
|
INSERT INTO t1 VALUES ( 70, 1 );
|
|
|
|
SELECT * FROM t1
|
|
|
|
WHERE
|
|
|
|
(
|
|
|
|
( b =1 AND a BETWEEN 14 AND 21 ) OR
|
|
|
|
( b =2 AND a BETWEEN 16 AND 18 ) OR
|
|
|
|
( b =3 AND a BETWEEN 15 AND 19 )
|
|
|
|
);
|
|
|
|
a b
|
|
|
|
DROP TABLE t1;
|
|
|
|
CREATE TABLE t1 ( a integer, u varchar(15), r integer, key uao_idx( r, a, u));
|
|
|
|
DELETE FROM t1
|
|
|
|
WHERE ( r = 1 AND a IN ( 1, 2 ) AND ( u = 'w' OR u LIKE 'w/%' ) )
|
|
|
|
OR ( r = 1 AND a IN ( 3 ) AND ( u = 'w/U' OR u LIKE 'w/U/%' ) )
|
|
|
|
OR ( r = 1 AND a IN ( 1, 2, 3 ) AND ( u = 'w' ) );
|
|
|
|
drop table t1;
|
2004-05-28 12:01:16 +02:00
|
|
|
CREATE TABLE t1 (a VARCHAR(16), UNIQUE(a));
|
|
|
|
INSERT INTO t1 VALUES ('1'), ('2'), ('3');
|
|
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a = '2' LIMIT 0, 1;
|
|
|
|
a
|
|
|
|
2
|
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
1
|
|
|
|
DROP TABLE t1;
|
|
|
|
CREATE TABLE t1 (a INT);
|
|
|
|
INSERT INTO t1 VALUES (0), (0), (1), (2);
|
|
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a = 0 GROUP BY a HAVING a > 10;
|
|
|
|
a
|
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
0
|
|
|
|
DROP TABLE t1;
|
2004-10-27 11:51:17 +02:00
|
|
|
SELECT 'foo';
|
|
|
|
foo
|
|
|
|
foo
|
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
1
|
|
|
|
SELECT SQL_CALC_FOUND_ROWS 'foo';
|
|
|
|
foo
|
|
|
|
foo
|
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
1
|
|
|
|
SELECT SQL_CALC_FOUND_ROWS 'foo' limit 0;
|
|
|
|
foo
|
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
1
|
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
1
|
|
|
|
SELECT SQL_CALC_FOUND_ROWS 'foo' UNION SELECT 'bar' LIMIT 0;
|
|
|
|
foo
|
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
2
|
2005-01-22 11:40:27 +01:00
|
|
|
CREATE TABLE t1 (a int, b int);
|
|
|
|
INSERT INTO t1 VALUES (1,2), (1,3), (1,4), (1,5);
|
|
|
|
SELECT SQL_CALC_FOUND_ROWS DISTINCT 'a' FROM t1 GROUP BY b LIMIT 2;
|
|
|
|
a
|
|
|
|
a
|
|
|
|
SELECT FOUND_ROWS();
|
|
|
|
FOUND_ROWS()
|
|
|
|
1
|
2005-02-28 10:59:46 +01:00
|
|
|
DROP TABLE t1;
|