SELECT SQL_CALC_FOUND_ROWS t2.* FROM t2 INNER JOIN t1 ON t2.IdDirectMessage = t1.IdDirectMessage WHERE IdUser = 4 AND Readed Is NULL UNION SELECT t2.* FROM t2 INNER JOIN t1 ON t2.IdDirectMessage = t1.IdDirectMessage WHERE IdUser = 4 AND NOT (t1.Readed is NULL) ORDER BY DateOfMessage Limit 0,2;
IdDirectMessage MessageData DateOfMessage
1 Texto 2003-08-06 00:00:00
2 Texto 2003-08-06 00:00:00
SELECT FOUND_ROWS();
FOUND_ROWS()
22
SELECT SQL_CALC_FOUND_ROWS t2.* FROM t2 INNER JOIN t1 ON t2.IdDirectMessage = t1.IdDirectMessage WHERE IdUser = 4 AND Readed Is NULL UNION ALL SELECT t2.* FROM t2 INNER JOIN t1 ON t2.IdDirectMessage = t1.IdDirectMessage WHERE IdUser = 4 AND NOT (t1.Readed is NULL) ORDER BY DateOfMessage Limit 0,2;
IdDirectMessage MessageData DateOfMessage
1 Texto 2003-08-06 00:00:00
2 Texto 2003-08-06 00:00:00
SELECT FOUND_ROWS();
FOUND_ROWS()
22
SELECT SQL_CALC_FOUND_ROWS t2.* FROM t2 INNER JOIN t1 ON t2.IdDirectMessage = t1.IdDirectMessage WHERE IdUser = 4 AND Readed Is NULL limit 1 UNION SELECT t2.* FROM t2 INNER JOIN t1 ON t2.IdDirectMessage = t1.IdDirectMessage WHERE IdUser = 4 AND NOT (t1.Readed is NULL) ORDER BY DateOfMessage;
IdDirectMessage MessageData DateOfMessage
1 Texto 2003-08-06 00:00:00
2 Texto 2003-08-06 00:00:00
3 Texto 2003-08-06 00:00:00
4 Texto 2003-08-06 00:00:00
5 Texto 2003-08-06 00:00:00
6 Texto 2003-08-06 00:00:00
7 Texto 2003-08-06 00:00:00
8 Texto 2003-08-06 00:00:00
9 Texto 2003-08-06 00:00:00
10 Texto 2003-08-06 00:00:00
11 Texto 2003-08-06 00:00:00
12 Texto 2003-08-06 00:00:00
13 Texto 2003-08-06 00:00:00
14 Texto 2003-08-06 00:00:00
15 Texto 2003-08-06 00:00:00
16 Texto 2003-08-06 00:00:00
17 Texto 2003-08-06 00:00:00
18 Texto 2003-08-06 00:00:00
19 Texto 2003-08-06 00:00:00
20 Texto 2003-08-06 00:00:00
21 Texto 2003-08-06 00:00:00
22 Texto 2003-08-06 00:00:00
SELECT FOUND_ROWS();
FOUND_ROWS()
22
drop table t2,t1;
CREATE TABLE t1 ( sid int(11) NOT NULL default '0', nazwa char(10) NOT NULL default '', PRIMARY KEY (sid) ) TYPE=MyISAM;
CREATE TABLE t2 ( id int(11) NOT NULL default '0', link int(11) default NULL, bubu char(10) NOT NULL default '', PRIMARY KEY (id) ) TYPE=MyISAM;
INSERT INTO t2 VALUES (1,2,'keke');
SELECT bubu, nazwa, bubu FROM t2 LEFT JOIN t1 ON sid = link WHERE id=1 UNION SELECT 'bu', null, 'bu';