Using Multiple WHERE Conditions In Single SQL Query

I'm wondering if there's a way to use WHERE condition in SQL more than once. Here's what I'm trying to achieve:-

Get the output in following format:-
[Username] [Article Contributed Last Month] [Total Articles Contributed]

Those are the columns, with the last column trying to pull the count of all articles contributed irrespective of the time. My query looks like this: -

SELECT xyz AS username, COUNT(abc) As count_last_month FROM pqr
INNER JOIN ...
ON ....
WHERE category = 2 AND date = ...condition to select dates in the last month
This query totally ignores the third column, where I need to fetch the total count of articles. For this, I should have to add another WHERE condition where I tweak the date = to get data for all the dates; not just the last month.

Can someone tell me how to do that?

Replies

  • Anoop Kumar
    Anoop Kumar
    Try following:
    select username, count(posts), (Subquery to get all post by username with join to main query)
    where daterange group by user name
  • Kaustubh Katdare
    Kaustubh Katdare
    Will definitely try that; but the query looks obnoxiously large ☕
  • Anoop Kumar
    Anoop Kumar
    yes, it will. You are trying to group to different counts in query.
    that Subquery will not work but there could be some workaround like HAVING clause.
  • Manish Goyal
    Manish Goyal
    #-Link-Snipped-#

    May be this discussion will help you?

You are reading an archived discussion.

Related Posts

Is any one had given Assistant Vigilance officer's exam of MAHADISCOM?
Hi All, mine is just curiosity in a field which is not mine (I'm a electronics eng. specialized in microwaves). The question is: would that be possible to build a...
can u tell me the explanation for fibonacci series program in java without using recursion??
So the thing is, I have a small (100 Page) book written on the basics of a designing software along with a few exercises and solution. Can you guys give...
The first thing that will attract your attention to the newly launched InFocus M260 Android smartphone priced at Rs. 3999, is its innovative catch line. Promoted as a mobile device...