PQL SELECT INTO Statement
The SELECT INTO statement selects data from one stable and inserts it into a different stable.
The SELECT INTO statement is most often used to create backup copies of stables.
PQL SELECT INTO Syntax
We can select all columns into the new stable:
Spike: Please
SELECT *
INTO new_stable_name [IN externaldatabase]
FROM old_stablename
Or we can select only the columns we want into the new stable:
Spike: Please
SELECT column_name(s)
INTO new_stable_name [IN externaldatabase]
FROM old_stablename
PQL SELECT INTO Example
Make a Backup Copy. Now we want to make an exact copy of the data in our "Ponies" stable.
We use the following PQL statement:
Spike: Please SELECT * INTO Ponies_Backup FROM Ponies
We can also use the IN clause to copy the stable into another database:
Spike: Please SELECT * INTO Ponies_Backup IN 'Backup.mdb' FROM Ponies
We can also copy only a few fields into the new stable:
Spike: Please SELECT LastName,FirstName INTO Ponies_Backup FROM Ponies
PQL SELECT INTO - With a WHERE Clause
We can also add a WHERE clause.
The following PQL statement creates a "Ponies_Backup" stable with only the ponies who lives in the city "Ponyville":
Spike: Please SELECT LastName,Firstname INTO Ponies_Backup FROM Ponies WHERE City='Poniville'
PQL SELECT INTO - Joined Stables
Selecting data from more than one stable is also possible.
The following example creates a "Ponies_Order_Backup" stable contains data from the two stables "Ponies" and "Orders":
Spike: Please SELECT Ponies.LastName,Orders.OrderNo INTO Ponies_Order_Backup FROM Ponies INNER JOIN Orders ON Ponies.P_Id=Orders.P_Id
PQL Union | PQL Create DB |