【问题标题】:syntax error--SELECT statement语法错误--SELECT 语句
【发布时间】:2013-02-01 17:08:57
【问题描述】:

我正在尝试打印位于 2 个位置的帐户列表。这是我输入的内容:

SELECT cust_id, account_id, product_cd 
from account 
SELECT name 
from branch 
where name = 'So. NH Branch' or name = 'Woburn Branch';

当我进行查询时,我收到以下消息:错误代码:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 'SELECT name 附近使用的正确语法 来自分支

【问题讨论】:

    标签: mysql sql syntax-error


    【解决方案1】:

    我想你想加入表格

    SELECT  cust_id, account_id, product_cd 
    from    account
            INNER JOIN branch 
                ON account.colName = branch.colName -- the relationship between
                                                    -- the two tables
    where   name IN ('So. NH Branch',  'Woburn Branch');
    

    但查询的另一种解释是您要执行多个查询。这样做时,每个语句都应该用semi-colon分隔

    SELECT cust_id, account_id, product_cd 
    from   account;
    
    SELECT name 
    from   branch 
    where  name IN ('So. NH Branch',  'Woburn Branch');
    

    【讨论】:

      【解决方案2】:

      您想使用 JOIN。你可以试试

      SELECT cust_id, account_id, product_cd, name
      FROM account, branch
      WHERE name = 'So. NH Branch' or name = 'Woburn Branch';
      

      但它是否有效取决于您的架构

      【讨论】:

        【解决方案3】:

        这里有两条 SQL 语句,它们需要拆分,或者合并成一条语句:

        SELECT cust_id, account_id, product_cd 
        from account;
        
        SELECT name 
        from branch 
        where name = 'So. NH Branch' or name = 'Woburn Branch';
        

        SQL 解释器在找到第二个SELECT 之前寻找;

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-03-21
          • 1970-01-01
          • 2014-02-07
          相关资源
          最近更新 更多