INSERT INTO CD
SELECT GNCJNC_CD.*
FROM GNCJNC_CD;
Monday, February 25, 2008
INSERT Example
I need to insert into one table from another. I found the following example code at this link: http://www.1keydata.com/sql/sqlinsert.html
INSERT INTO "table1" ("column1", "column2", ...)
SELECT "column3", "column4", ...
FROM "table2"
Note that this is the simplest form. The entire statement can easily contain WHERE, GROUP BY, and HAVING clauses, as well as table joins and aliases.
So for example, if we wish to have a table, Store_Information, that collects the sales information for year 1998, and you already know that the source data resides in the Sales_Information table, we'll type in:
INSERT INTO Store_Information (store_name, Sales, Date)
SELECT store_name, Sales, Date
FROM Sales_Information
WHERE Year(Date) = 1998
INSERT INTO "table1" ("column1", "column2", ...)
SELECT "column3", "column4", ...
FROM "table2"
Note that this is the simplest form. The entire statement can easily contain WHERE, GROUP BY, and HAVING clauses, as well as table joins and aliases.
So for example, if we wish to have a table, Store_Information, that collects the sales information for year 1998, and you already know that the source data resides in the Sales_Information table, we'll type in:
INSERT INTO Store_Information (store_name, Sales, Date)
SELECT store_name, Sales, Date
FROM Sales_Information
WHERE Year(Date) = 1998
Friday, June 8, 2007
Synonym (SQL 2005)
This a new feature in SQL 2005. It provides aliasing at the database level. It is similar to the 'AS' command that provides aliasing at the query level. (See article http://builder.com.com/5100-6388_.html?part=rss&tag=feed&subj=bldr)
Example:
USE Inventory
GO
CREATE SYNONYM SalesHistory
FOR SalesData.dbo.SalesHistory;
GO
Example:
USE Inventory
GO
CREATE SYNONYM SalesHistory
FOR SalesData.dbo.SalesHistory;
GO
Wednesday, June 6, 2007
RIGHT JOIN
The same as a left join but the table order is changed.
Returns all the rows from the second table, even if there are no matches in the first table.
This is a good means of find elements in one table but not in another.
Syntax:
SELECT field1, field2, field3, ... fieldN
FROM first_table
RIGHT JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield;
(see http://www.w3schools.com/sql/sql_join.asp)
Returns all the rows from the second table, even if there are no matches in the first table.
This is a good means of find elements in one table but not in another.
Syntax:
SELECT field1, field2, field3, ... fieldN
FROM first_table
RIGHT JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield;
(see http://www.w3schools.com/sql/sql_join.asp)
Wednesday, May 23, 2007
SQL Parser
It looks like there is one in Java, PHP.
I might be able to use code from SQLLight, but there is no nice clean library that I can just call.
http://www.sqlite.org/arch.html
I might be able to use code from SQLLight, but there is no nice clean library that I can just call.
http://www.sqlite.org/arch.html
Friday, April 13, 2007
Subscribe to:
Posts (Atom)