johnnyg123
asked on
sql to add additional rows
Here is some sample data from the order and customer tables (SQL Server 2014)
Order Table
OrderID OrderAmount
1 300
2 400
Customer Table
CustomerID CustomerFirstName CustomerLastName
500 Fred Smith
Need to write a query that will return all rows from customer table with a row for each order that exists
Given sample data would like query to return the following
CustomerID CustomerFirstName CustomerLastName OrderID OrderAmount
500 Fred Smith 1 300
500 Fred Smith 2 400
Not sure of best way to do this
Order Table
OrderID OrderAmount
1 300
2 400
Customer Table
CustomerID CustomerFirstName CustomerLastName
500 Fred Smith
Need to write a query that will return all rows from customer table with a row for each order that exists
Given sample data would like query to return the following
CustomerID CustomerFirstName CustomerLastName OrderID OrderAmount
500 Fred Smith 1 300
500 Fred Smith 2 400
Not sure of best way to do this
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
>>from Customer c, Order o
That will work but probably better to use the new ANSI join syntax.
That will work but probably better to use the new ANSI join syntax.
Hi,
Try
Try
select a.*,b.*
from customertable,ordertable
I think better to have/add customerID column (as one foreign key) in Ordertable, to know which customer does make which order.
@Peter,
Please review previous Experts comments. That has already been posted.
and yours is incorrect. You cannot select a.* if you don't alias the tables.
Please review previous Experts comments. That has already been posted.
and yours is incorrect. You cannot select a.* if you don't alias the tables.
:: snicker :: This question was answered in the first comment, with helpful commentary.
Open in new window
But you really want to know what you want to return, and if this is the expected result