Does the order of columns matter in SQL statement

Database

Does the order of columns matter in SQL statement

Hi all,

I am completly new to teradata. I have a query to run in SQL assistant which has some calculated columns. I wonder if order of the columns matter. For example when 1st column depends on 2nd column like

Select

A1 - A1NC   AS A1C,

SUM(CASE WHEN IND = 1 THEN 1 ELSE 0 END) AS A1,

B1

From table

Since A1C depends on A1 , Sould A1 be the 1st column or order doen't matter?  Please can anyone clarify this for me?

Thanks,

Jyo

2 REPLIES
Enthusiast

Re: Does the order of columns matter in SQL statement

Hi Jyo,

No the sequence of columns doesn't matter as long as they are in the same SQL scope. Your query should run fine.

Regards,

Qaisar Aftab Kiani.

Enthusiast

Re: Does the order of columns matter in SQL statement

Order of the columns doesn't make problem. if you are selecting fileds with aggregate function used in query, you shoud have to do GROUP BY. otherwise non-aggregate problem will occur.

Try the below query, it works

sel A1-A1NC as A1C, A1,B1  from (sel sum(case when IND=1 then 1 else 0 end) A1 from TN)t,TN

sel (sel sum(case when IND=1 then 1 else 0 end) A1 from TN)-A1NC as A1C, B1 from TN