[SOLVED] SQL Alias problem... point out my error please.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi Everyone,
I'm having some difficulties understanding why this isn't working. why would some alias work and some doesn't? Could someone point out what I'm doing wrong?
While not using Alias for t1.PARENT and t2.PROJECT_ID, it works without any errors.
without alias for t1.PARENT & t2.PROJECT_ID
Code:
SELECT t1.PARENT, t2.PROJECT_ID, t2.PROJECT_NAME AS PARENT_NAME
FROM TABLE1 t1 INNER JOIN TABLE1 t2
ON t1.PARENT = t2.PROJECT_ID
ORDER BY PARENT_NAME ASC
using alias PARENTID & PROJECTID
Code:
SELECT t1.PARENT AS PARENTID, t2.PROJECT_ID AS PROJECTID, t2.PROJECT_NAME AS PARENT_NAME
FROM TABLE1 t1 INNER JOIN TABLE1 t2
ON PARENTID = PROJECTID
ORDER BY PARENT_NAME ASC
causes
Code:
ERROR: An undefined column or parameter name was detected.
Last edited by struct; 01-17-2011 at 02:21 PM.
Reason: edited to make it easier to understand.
Well, I believe this is no standard SQL, so it depends on your database server (you didn't
say which...). I believe PostgreSQL can do that, MS SQL Server can't...
Cheers, Tom...
Paulsm4,
thank you for taking your time to illustrate that. Unfortunately putting a single quote around the alias causes same error in my system. Your method worked because you joined the columns with tableAlias.column name instead of column Alias.
Cheesus,
I'm on DB2.
Tinkster,
Your answer is sound but ORDER BY PARENT_NAME works on my system. So... I don't think your answer applies here.
Anyways, I decided to go with Paulsm4's method. Thank you for giving me your valuable input.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.