0

我正在尝试打印位于 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 from branch 附近使用的正确语法

4

3 回答 3

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');
于 2013-02-01T17:14:27.467 回答
0

您想使用 JOIN。你可以试试

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

但这取决于您的架构是否会起作用

于 2013-02-01T17:14:43.293 回答
0

你这里有两条 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

于 2013-02-01T17:14:57.997 回答