列模糊地定义了sql plus

时间:2016-04-19 13:31:18

标签: sql oracle

我试图在sql plus中运行它,但它给了我这个错误

 SELECT reviewer_address, reviewer_name, review_date
FROM reviewers, reviews
INNER JOIN reviews ON reviewers.reviewer_address = reviews.review_date
INNER JOIN reviewers ON reviews.review_date = reviewers_address;

 ERROR at line 1:
ORA-00918: column ambiguously defined

有谁知道我做错了什么?

这些是评论和评论者的表格

CREATE TABLE reviewers  (
    reviewer_id         NUMBER (6),
    reviewer_name       VARCHAR2 (30),
    review_name         VARCHAR2 (15), 
    reviewer_address    REF address_type SCOPE IS addresses
);

CREATE TABLE reviews    (
    review_id           NUMBER (6),
    review_name         VARCHAR2 (30),
    review_date         DATE,
    reviewer_id         NUMBER (6) NOT NULL,
    venue_id            NUMBER (6) NOT NULL
);

这些是他们两个表的插入

--reviews
INSERT INTO reviews (review_id, review_name, review_date, reviewer_id, venue_id)
VALUES (1, 'MIKE POWELL', '03-DEC-2015', 1, 1);

INSERT INTO reviews (review_id, review_name, review_date, reviewer_id, venue_id)
VALUES (2, 'JOHN MAYER', '15-MAY-2004', 2, 2);

INSERT INTO reviews (review_id, review_name, review_date, reviewer_id, venue_id)
VALUES (3, 'SETH CONNOR', '25-JAN-2011', 3, 3);

INSERT INTO reviews (review_id, review_name, review_date, reviewer_id, venue_id)
VALUES (4, 'JULIA SMITH', '08-AUG-2013', 4, 4);

INSERT INTO reviews (review_id, review_name, review_date, reviewer_id, venue_id)
VALUES (5, 'MADONNA MARLEY', '30-NOV-2001', 5, 5);


--reviewers
INSERT INTO reviewers (reviewer_id, reviewer_name, review_name, reviewer_address)
SELECT 1, 'MIKE POWELL', 'TEST REVIEW', REF(a)
FROM addresses a
WHERE street = '13 JAMES ROAD';

INSERT INTO reviewers (reviewer_id, reviewer_name, review_name, reviewer_address)
SELECT 2, 'JOHN MAYER', 'MAIN REVIEW', REF(a)
FROM addresses a
WHERE street = '54 BRIDGE STREET';

INSERT INTO reviewers (reviewer_id, reviewer_name, review_name, reviewer_address)
SELECT 3, 'SETH CONNOR', 'CAR REVIEW', REF(a)
FROM addresses a
WHERE street = '10 LIME STREET';

INSERT INTO reviewers (reviewer_id, reviewer_name, review_name, reviewer_address)
SELECT 4, 'JULIA SMITH', 'BEAUTY REVIEW', REF(a)
FROM addresses a 
WHERE street = '1 PALL MALL STREET';

INSERT INTO reviewers (reviewer_id, reviewer_name, review_name, reviewer_address)
SELECT 5, 'MADONNA MARLEY', 'CLOTHES REVIEW', REF(a)
FROM addresses a
WHERE street = '28 MAIN ROAD';

我希望这会让你们更容易

2 个答案:

答案 0 :(得分:1)

永远不要将旧的隐式连接语法与现代的显式JOIN语法混合使用。 并且不要复制选择列表中的表格。

SELECT reviewer_address, reviewer_name, review_date
FROM reviewers
INNER JOIN reviews ON reviewers.reviewer_id = reviews.reviewer_id

答案 1 :(得分:0)

请使用:

SELECT reviewer_address, reviewer_name, review_date
FROM reviewers, reviews
where reviewers.reviewer_address = reviews.review_date

或者

SELECT reviewer_address, reviewer_name, review_date
FROM reviewers
INNER JOIN reviews ON reviewers.reviewer_address = reviews.review_date