Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DB2 SQL Select All With Columns As

I am working with some SQL queries on DB2. Is it possible to select all the columns in a table and also specify certain conditions using the "as" keyword within that select statement? For example, is this query possible:

select
  *,
  col1 + col2 as sum1,
  col3 - col4 as dif1
from 
  table;

Whenever I attempt this, I am getting the SQL0104 error and it is saying "Token , was not valid. Valid tokens: FROM INTO".

Thank you for your help.

EDIT: This query is running inside an SQLRPGLE program on an AS400.

like image 293
jallen3095 Avatar asked Aug 01 '26 23:08

jallen3095


1 Answers

Put your table alias in front of the *. So:

select
  t.*,
  col1 + col2 as sum1,
  col3 - col4 as dif1
from 
  table t;
like image 99
JoeWilson Avatar answered Aug 04 '26 13:08

JoeWilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!