Jump to content

Alias for Tables Example


hk21

Recommended Posts

The following SQL statement selects all the orders from the customer with CustomerID=4 (Around the Horn). We use the "Customers" and "Orders" tables, and give them the table aliases of "c" and "o" respectively (Here we use aliases to make the SQL shorter): 

 

What does this example mean: How is it giving only 2 order id's from order table when there are many rows with employee id=4 in the orders table

Example

SELECT o.OrderID, o.OrderDate, c.CustomerName
FROM Customers AS c, Orders AS o
WHERE c.CustomerName="Around the Horn" AND c.CustomerID=o.CustomerID;
Try it Yourself »
Link to comment
Share on other sites

This SQL is filtering by CustomerName of Around the horn, equivalenting to a CustomerID of 4. This is not the same as an employeeID.

IF you look closely at the returned set, you'll find that the two records have an employeeID of 6 and 8 respectively.

CustomerID CustomerName ContactName Address City PostalCode Country OrderID EmployeeID OrderDate ShipperID
4 Around the Horn Thomas Hardy 120 Hanover Sq. London WA1 1DP UK 10355 6 1996-11-15 1
4 Around the Horn Thomas Hardy 120 Hanover Sq. London WA1 1DP UK 10383 8 1996-12-16 3
Link to comment
Share on other sites

  • 1 month later...

Hello, @hk21

Please try this query,To Alias for Tables :

select s.state_name,c.city_name,a.area_name from State as s,Area as a,City as c where a.city_id=c.city_id AND c.state_id=s.state_id;

We use the State,City and Area tables and give them the table aliases of s,c and a respectively.

I hope above query will be useful for you.

Thank you.

 

 

Edited by Makwana Prahlad
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...