2016-07-25 39 views
0

DB2データベースクエリのすべての列を表示したいが、特定の列を前面に配置したい。私は怖いDB2クエリーで特定のフィールドとスターを選択するにはどうすればよいですか?

SQL State: 42601 
Vendor Code: -104 
Message: [SQL0104] Token * was not valid. Valid tokens: (+ - ? : DAY INF NAN RID ROW RRN CASE CAST CHAR DATE DAYS HASH. Cause . . . . . : A syntax error was detected at token *. 
Token * is not a valid token. A partial list of valid tokens is (+ - ? : DAY INF NAN RID ROW RRN CASE CAST CHAR DATE DAYS HASH. 
This list assumes that the statement is correct up to the token. 
The error may be earlier in the statement, but the syntax of the statement appears to be valid up to this point. Recovery . . . : 
Do one or more of the following and try the request again: -- Verify the SQL statement in the area of the token *. 
Correct the statement. The error could be a missing comma or quotation mark, it could be a misspelled word, or it could be related to the order of clauses. 
-- If the error token is <END-OF-STATEMENT>, correct the SQL statement because it does not end with a valid clause. 

Processing ended because the highlighted statement did not complete successfully 

答えて

2

あなたはそうのように、相関名を使用して、この操作を行うことができますので、Field1が結果に2回表示されます、すべての列を返すtbl.*、明らかに

SELECT Field1, tbl.* FROM YourTable tbl 

+0

ありがとう@mustaccioこれは完全に機能しました。 –

0

以下のように上記のクエリがエラーを返しているしかし、あなたが選択する必要があります

SELECT Field2, * FROM Table 

のようなものを書くと私のSQLの知識から、例えば

各列は別々にlike

select field_you_want_to_appear_first, field2, filed3.. from yourtable 
1

以下のようにビューを使用できます。

[email protected]:/home/db2inst1:>db2 "select * from mytable" 

VAL NEW_VAL 
--- ------- 
5 -  
6 -  
A -  

    3 record(s) selected. 

[email protected]:/home/db2inst1:>db2 "CREATE VIEW MYTABLEVW AS SELECT NEW_VAL,VAL FROM MYTABLE" 
DB20000I The SQL command completed successfully. 

[email protected]:/home/db2inst1:>db2 "select * from mytablevw" 

NEW_VAL VAL 
------- --- 
-  5 
-  6 
-  A 

    3 record(s) selected. 
+1

私はあなたがこれで行くところを見ます。それは動作しますが、私が必要とするもののオーバーヘッドを少し追加します。私にはちょっと簡単な@ mustaccioの答えを見てください。 –

関連する問題