3

I have the following query

SELECT *
FROM
              ( select distinct
                      r1.rep_code,
                      r1.contact_id,
                      c1.Name,
                      e1.year_num,
                      e1.period_num
                   from
                      entry e1
                         join rep r1 ON e1.rep_code = r1.rep_code
                            join contact c1 on r1.contact_id = c1.contact_id
                   where
                          e1.entry_type = 'SJOB'
                      and e1.age = 0 )

I keep getting an error on line 3

Token unknown - line 3, char 15
select

can you please advice, by the way im using interbase IBConsole !!

Adriano Carneiro
  • 53,285
  • 12
  • 85
  • 120
c11ada
  • 4,182
  • 14
  • 43
  • 62

5 Answers5

3

Apparently, Interbase does not support derived tables (SELECT FROM (SELECT)). Or, at least, the version you are using (I cannot be sure, it's been a while since I don't work with Interbase). This feature was added in Firebird 2.0. You have two options here:

  • Change your approach so that you don't use SELECT FROM (SELECT) (derived tables)

    OR

  • Upgrade to Firebird

If you have autonomy for that, you should definitively go with option #2.

BTW, Firebird does not require you to declare an alias for your derived table, although that will end up being necessary if you will have your derived table JOINED with other table(s)/derived table(s)

Adriano Carneiro
  • 53,285
  • 12
  • 85
  • 120
2

You need to give the subquery an alias.

SELECT *
FROM
          ( select distinct
                  r1.rep_code,
                  r1.contact_id,
                  c1.Name,
                  e1.year_num,
                  e1.period_num
               from
                  entry e1
                     join rep r1 ON e1.rep_code = r1.rep_code
                        join contact c1 on r1.contact_id = c1.contact_id
               where
                      e1.entry_type = 'SJOB'
                  and e1.age = 0 ) AS tbl
Oded
  • 463,167
  • 92
  • 837
  • 979
2

InterBase doesn't support derived tables. But they give you no benefit for this query, so just get rid of it:

              select distinct
                  r1.rep_code,
                  r1.contact_id,
                  c1.Name,
                  e1.year_num,
                  e1.period_num
               from
                  entry e1
                     join rep r1 ON e1.rep_code = r1.rep_code
                        join contact c1 on r1.contact_id = c1.contact_id
               where
                      e1.entry_type = 'SJOB'
                         and e1.age = 0 

...will give you the same results as a derived table would in this case..

Craig Stuntz
  • 123,797
  • 12
  • 247
  • 268
0
SELECT *
FROM
              ( select distinct
                      r1.rep_code,
                      r1.contact_id,
                      c1.Name,
                      e1.year_num,
                      e1.period_num
                   from
                      entry e1
                         join rep r1 ON e1.rep_code = r1.rep_code
                            join contact c1 on r1.contact_id = c1.contact_id
                   where
                          e1.entry_type = 'SJOB'
                      and e1.age = 0 ) AS TABLE1
Gabriele Petrioli
  • 173,972
  • 30
  • 239
  • 291
CodeRunner
  • 33
  • 2
0

I got this error:

# 1248 - Every derived table must have its own alias

try something like:

SELECT *
FROM
              ( select distinct
                      r1.rep_code,
                      r1.contact_id,
                      c1.Name,
                      e1.year_num,
                      e1.period_num
                   from
                      entry e1
                         join rep r1 ON e1.rep_code = r1.rep_code
                            join contact c1 on r1.contact_id = c1.contact_id
                   where
                          e1.entry_type = 'SJOB'
                      and e1.age = 0 ) AS entries
Gabriele Petrioli
  • 173,972
  • 30
  • 239
  • 291
Juris Malinens
  • 1,203
  • 1
  • 9
  • 13