0

Trying to do a simple FULL OUTER JOIN on a timestamp and it is outputing the full cartesian product instead of matching identical dates. What is wrong here?

SQL Fiddle with example data

CREATE TABLE A (
    id INT,
    time TIMESTAMP
);

CREATE TABLE B (
     id INT,
     time TIMESTAMP
);

Query:

SELECT A.Id AS a_id, A.Time AS a_time, B.Id AS b_id, B.Time AS b_time 
FROM A
FULL OUTER JOIN B ON A.Time = B.Time

-- This works:
-- SELECT A.id, A.time, B.id, B.time
-- FROM A
-- FULL OUTER JOIN B ON A.id = B.id
3
  • What result you expect? Commented Nov 7, 2017 at 20:28
  • The same thing as the commented out query. Commented Nov 7, 2017 at 20:29
  • A full outer join produces a cartesian product by definition. Maybe you mean inner join? Commented Nov 7, 2017 at 21:25

2 Answers 2

2

You are using the wrong parameters on TO_DATE() on your INSERTS easy to test if you do

SELECT * FROM A; 
SELECT * FROM B;

Instead of

 TO_DATE('01-01-2002', '%d-%m-%Y')

Should be:

 TO_DATE('01-01-2002', '%DD-%MM-%Y')

SQL DEMO

Sign up to request clarification or add additional context in comments.

Comments

1

In your sql fiddle all your inserted dates are the same because your date pattern is wrong. Try using TO_DATE('01-01-2002', 'DD-MM-YYYY') instead of TO_DATE('01-01-2002', '%d-%m-%y')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.