Here is the query you need:
SELECT name FROM
(
SELECT name FROM table1
UNION
SELECT name FROM table2
) A;
Here is some sample code based on your question:
use test
drop table if exists table1;
drop table if exists table2;
create table table1
(
id int not null auto_increment,
name varchar(10),
primary key (id)
);
create table table2 like table1;
insert into table1 (name) values ('A'),('B'),('C');
insert into table2 (name) values ('C'),('D'),('E');
SELECT name FROM
(
SELECT name FROM table1
UNION
SELECT name FROM table2
) A;
Here is the execution of that sample code:
mysql> drop table if exists table1;
Query OK, 0 rows affected (0.03 sec)
mysql> drop table if exists table2;
Query OK, 0 rows affected (0.03 sec)
mysql> create table table1 (
-> id int not null auto_increment,
-> name varchar(10),
-> primary key (id)
-> );
Query OK, 0 rows affected (0.05 sec)
mysql> create table table2 like table1;
Query OK, 0 rows affected (0.06 sec)
mysql> insert into table1 (name) values ('A'),('B'),('C');
Query OK, 3 rows affected (0.06 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> insert into table2 (name) values ('C'),('D'),('E');
Query OK, 3 rows affected (0.11 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> SELECT name FROM (SELECT name FROM table1
-> UNION SELECT name FROM table2) A;
+------+
| name |
+------+
| A |
| B |
| C |
| D |
| E |
+------+
5 rows in set (0.00 sec)
mysql>
Give it a Try !!!
If filter 110M
is exactly a subset of filter 126M
, then appending more AND
with WHERE
would have done the job.
$sql1 = "SELECT ..... WHERE ...";
$sql2 = $sql1 . "AND column-name = ....";
$sql3 = $sql2 . "AND column-name = ....";
If that is complex to accomplish try to CREATE VIEW of the previous SELECT statement and the next SELECT statement should query from the view.
Best Answer
If you really need it (I don't get why though), you can do