使用SQL Developer中多个表的信息

时间:2013-11-25 04:02:40

标签: sql database oracle oracle-sqldeveloper

我试图让这个SQL语句工作,我似乎无法让它显示我要求的信息。我得到的错误是SQL命令没有在从lg品牌中选择brand_name的行正确结束。

SELECT CUST_FNAME, CUST_LNAME, CUST_STREET, CUST_CITY, CUST_STATE, CUST_ZIP
FROM LGCUSTOMER 
SELECT BRAND_NAME FROM LGBRAND
WHERE BRAND_NAME = 'FORESTERS BEST'
SELECT INV_DATE FROM LGINVOICE
WHERE INV_DATE BETWEEN '2011-15-07' AND '2011-31-07'
ORDER BY CUST_STATE, CUST_LNAME, CUST_FNAME;

2 个答案:

答案 0 :(得分:0)

您运行的是MS SQL还是MySQL?

如果这是MySQL,那么你需要用分号结束每个单独的语句,如:

SELECT CUST_FNAME, CUST_LNAME, CUST_STREET, CUST_CITY, CUST_STATE, CUST_ZIP
FROM LGCUSTOMER;
SELECT BRAND_NAME FROM LGBRAND
WHERE BRAND_NAME = 'FORESTERS BEST';
SELECT INV_DATE FROM LGINVOICE
WHERE INV_DATE BETWEEN '2011-15-07' AND '2011-31-07'
ORDER BY CUST_STATE, CUST_LNAME, CUST_FNAME;

编辑:我看到问题被标记为MS SQL,但错误闻起来像MySQL。

答案 1 :(得分:0)

不确定,你想要实现什么。但对我来说,看起来你有不同的查询,所以一个接一个地执行它们并用分号分隔它们:

SELECT CUST_FNAME, CUST_LNAME, CUST_STREET, CUST_CITY, CUST_STATE, CUST_ZIP
FROM LGCUSTOMER
ORDER BY CUST_STATE, CUST_LNAME, CUST_FNAME;

SELECT BRAND_NAME FROM LGBRAND;
WHERE BRAND_NAME = 'FORESTERS BEST';

SELECT INV_DATE FROM LGINVOICE
WHERE INV_DATE BETWEEN '2011-15-07' AND '2011-31-07';

如果您想在一个查询中使用所有条件,请使用:

SELECT a.CUST_FNAME, a.CUST_LNAME, a.CUST_STREET, a.CUST_CITY, a.CUST_STATE, a.CUST_ZIP,
  b.BRAND_NAME,
  c.INV_DATE
FROM LGCUSTOMER a, LGBRAND b, LGINVOICE c
WHERE b.BRAND_NAME = 'FORESTERS BEST'
AND c.INV_DATE BETWEEN '2011-15-07' AND '2011-31-07'
ORDER BY a.CUST_STATE, a.CUST_LNAME, a.CUST_FNAME;