Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

SQL Server Select statement

How do I use this the SELECT statement to select values from two different tables with the same field name. I get errors (column names must be unique in each view or function) when compiling: Select tblOne.fieldname, tblTwo.fieldname.
[234 byte] By [CB77] at [2007-11-11 10:31:58]
# 1 Re: SQL Server Select statement
What is the rest of the query?

do you alias the tables (e.g select blah from customers c)?

if you alias the tables in the from clause you must use their alias in the select list. or have i misunderstood your question?
Dale.Turley at 2007-11-11 23:43:16 >
# 2 Re: SQL Server Select statement
My code:

CREATE VIEW TotalPurchases
AS
SELECT tblSupplier.Name, tblProduct.Name, (qtyShip * tblPODetail.price) AS Sales
FROM tblPODetail
LEFT OUTER JOIN tblProduct
ON tblPODetail.ProductID = tblProduct.ProductID
LEFT OUTER JOIN tblSupplier
ON tblProduct.SupplierID = tblSupplier.SupplierID
CB77 at 2007-11-11 23:44:16 >
# 3 Re: SQL Server Select statement
You need to alias the two colums

SELECT tblSupplier.Name as "Supplier 1", tblProduct.Name as "Supplier 2", (qtyShip * tblPODetail.price) AS Sales
FROM tblPODetail
Dale.Turley at 2007-11-11 23:45:20 >