如何在DB2查询中选择特定字段和星号?

时间:2016-07-25 06:59:49

标签: sql db2

我想查看DB2数据库查询中的所有列,但是我想在前面放置一个列。

例如,根据我的SQL知识,我会写一些类似

的内容
SELECT Field2, * FROM Table

但是上面的查询返回的错误如下所示

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

3 个答案:

答案 0 :(得分:3)

您可以使用相关名称来执行此操作,如下所示:

SELECT Field1, tbl.* FROM YourTable tbl

显然,tbl.*会返回所有列,因此Field1会在结果中出现两次。

答案 1 :(得分:1)

您可以使用以下视图;

<?php
namespace myGuzzle;

require __DIR__.'/../vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;

class myGuzzle{


    public $params;
    public $method;
    public $endpoint;
    public $body;
    public $status;
    public $errorJson;


    function response($params=[],$method,$endpoint) {

        $this->params = $params;
        $this->method = $method;
        $this->endpoint = $endpoint;
             $client = new Client();
             try{

            $response = $client->request($this->method, $this->endpoint,['json' => $this->params]);

             $this->body = $response->getBody();
             $this->status = $response->getStatusCode();

             }

             catch(ClientException $e){


             $this->body = $e->getMessage();
             $this->status = $e->getCode();
             $this->errorJson = $e->getResponse()->getBody();
                }


    }



     function getStatus(){

         return $this->status;
     }   
     function getBody(){
         return $this->body;

     }
     function getErrorJson(){

         return $this->errorJson;
     }
}

答案 2 :(得分:0)

我担心,您必须分别选择每一列。喜欢

select field_you_want_to_appear_first, field2, filed3.. from yourtable