Table Alias

Hi,

I'm trying to perform a self join e.g.:

select a.name, b.age

from users a, users b;

However, I get a

java.sql.SQLException: [SQL0104] Token A was not valid. Valid tokens: , FROM INTO.

What syntax should I use on the from clause to set up the alias?

Thanks.

Paul.

[324 byte] By [paul_uka] at [2007-11-27 2:07:45]
# 1
What DB are you using?
masijade.a at 2007-7-12 1:56:19 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
I'm using DB2 on an iSeries.
paul_uka at 2007-7-12 1:56:19 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
Try using the "AS" keywordusers as a, users as b
masijade.a at 2007-7-12 1:56:19 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
I did try that and got:java.sql.SQLException: [SQL0199] Keyword AS not expected. Valid tokens: , FROM INTO.
paul_uka at 2007-7-12 1:56:19 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
Post the actual query (as it is in the code, with th code around it) I have a feeling that you are forgetting a space in one of your strings.Edit: Probably a space on both sides of the word "from".
masijade.a at 2007-7-12 1:56:19 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

Your absolutely right Masijade

My code was:

StringBuffer sb = new StringBuffer("select a.name, b.age");

sb.append("from users a, users b");

I have now inserted a space after b.age

at it now works fine.

Thank you.

paul_uka at 2007-7-12 1:56:19 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...