4

I'm using Sybase ASE 12.5.0.3 and I'm unable to do subqueries like:

select * from (select '1' union select '2' ) X

I've been looking around and as far as I know it should be possible after Sybase ASE 12, am I doing something wrong, or is it not possible with this version???

Edit - Even after changing the query to:

select * from (select '1' as col1 union select '2' as col1 ) X

So even giving alias to the columns, it fails anyways...

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
DarkAjax
  • 15,955
  • 11
  • 53
  • 65

3 Answers3

6

Without seeing an error message, it appears that you need to give column aliases in your sub-query:

select * 
from 
(
    select '1' as yournewCol 
    union 
    select '2' as yournewCol
) X
Taryn
  • 242,637
  • 56
  • 362
  • 405
1

You need to give your columns name. Try this:

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
1

Sybase ASE does not support subqueries in the FROM clause:

Subqueries can be nested inside the where or having clause of an outer select, insert, update, or delete statement, inside another subquery, or in a select list. Alternatively, you can write many statements that contain subqueries as joins; Adaptive Server processes such statements as joins.

yoroto
  • 97
  • 1
  • 2
  • I don't think the above quote is quite correct. Sybase refers to the OP syntax as "SQL-Derived Tables" which is basically what we'd consider as a subquery in a FROM clause - supported as early as 12.5.1. I just tried the OP's fixed version in ASE 15.7 and it worked fine (the one without column names did not work). http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc32300.1570/html/sqlug/sqlug198.htm – David Storfer Apr 12 '19 at 18:26