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 !!!
The words "securely", "exposing", "outside" and "database" do not belong together.
Under no circumstance should you ever expose a SQL server to the internet. It's a very bad idea.
So your question really should be: How do we give access to our SQL server to remote locations?
The answer: VPN. The remote users should establish a VPN connection to your network. From there you can give them the appropriate access to the database.
Best Answer
This code should achieve what you want
Sample output: