0

I have a table that I wish to select from. I want to select the same column twice, once with some date based filtering in the WHERE clause, and again without the filtering. How can I go about doing this?

Thanks

1
  • With 1000 rep I'm surprised you haven't written a better question. Table definitions/sample data, PostgreSQL version, desired results, etc. Commented May 16, 2013 at 2:10

1 Answer 1

2

Use a UNION query, possibly with a CTE.

You haven't provided table definitions so I can't provide real SQL. You're looking for something like this:

SELECT *
FROM thetable
WHERE ...datefilter ...
UNION ALL
SELECT *
FROM thetable
WHERE ... otherfilter...;

You may find common table expressions ("WITH" queries) useful too.

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

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.