Jump to content
Sign in to follow this  
hk21

Alias for Tables Example

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 »

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...