I did not really understand the benifit of the alias clause...

this was in the w3shools tatourial

with alias
SELECT po.OrderID, p.LastName, p.FirstName
FROM Persons AS p,
Product_Orders AS po
WHERE p.LastName='Hansen' AND p.FirstName='Ola'

with out alias

SELECT Product_Orders.OrderID, Persons.LastName, Persons.FirstName
FROM Persons,
Product_Orders
WHERE Persons.LastName='Hansen' AND Persons.FirstName='Ola'

why we just write it as smiple select statment like this

SELECT OrderID, LastName, FirstName
FROM Persons,Product_Orders
WHERE LastName='Hansen' AND FirstName='Ola'

can anyone help me to figer out the deffrence ?!! :S

btw anyone can leade me to a tutorial about nested SQL statements like Nested select etc...

or free oracle quiz

Hi,

It's quite simple. You must use aliases in your selects if you got same column name in two tables you are selecting from, e.g.

select a.name as "empl_name", b.name as "comp_name" from empl a, companies b where b.compid=a.id;

I hope it's clear now ;)

you can write whatever way u comfortable, sql have allow both option with and without aliases,

uses of alias in my view
1) so many times query use function and expression having so many columns involved, that is to be named with some alias to refer in better way in ur programming language
2) suppose you want to refer same column twice(for whatever reason), to distinguish, u may call like

select colA as firstA, colA as SecondA

3) when query is big, and you join so many table say 10 table, so its nice for some lazy programmer (like me) to just give alias for long table name to make query quick and short

YOU ARE FREE TO NOT USE ALIAS

@urtrivedi thanks alot
@ORAfreak un nice and the meaning of "a.name" is like in c# when your ponting to obiect or variable but here ur pointing to the column "name"from the table "a"
ummmm

in c# we do that because we cant access the column "name" without pointing to it to talble

am I understanding it right now ??? hope so

btw way is there any program that Simulate like im working on database and make query to practice ??

@pritaeas Wooooooooooooooooow Thanks alot thanks :))
wloud you mind to take alook here an sugest something to me it my child dream and I wont to losse it
Click Here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.