开发者

Please solve following query related to SQL [closed]

开发者 https://www.devze.com 2023-04-02 11:12 出处:网络
It's difficult to tell what is being asked here. This question is amb开发者_运维问答iguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.
It's difficult to tell what is being asked here. This question is amb开发者_运维问答iguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

My table contains ID and ID1

ID  ID1
5   8
6   9
7   1

Now The result set should like This

ID  ID1
8   5
9   6
1   7


SELECT ID1 as 'ID'
     , ID  as 'ID1'
FROM   <your table name>

If I understand you correctly it looks like you want to switch the field names.


select ID ID1, ID1 ID from tablename;


ID  ID1
5   8
6   9
7   1

As you have mention you just want ID1 column first then ID so in select statement you have to specify ID1 column first,then ID like this.

  SELECT ID1 'ID',ID 'ID1' FROM tablename;

so in above statement 'ID' is alias for ID1 and 'ID1' is alias for ID.


If you are referring to the order of the columns in the output you can change it after the SELECT keyword:

SELECT a, b FROM ...
SELECT b, a FROM ...

The first query will have column a first, the second query will have column b first

0

精彩评论

暂无评论...
验证码 换一张
取 消