WHY dont show all month with where

User avatar
sal21
PlatinumLounger
Posts: 4354
Joined: 26 Apr 2010, 17:36

WHY dont show all month with where

Post by sal21 »

Code: Select all

SELECT MESI.MM, MESI.MESE, Count(PRENOTAZIONI.IDTIP)
FROM PRENOTAZIONI RIGHT JOIN MESI ON PRENOTAZIONI.MM = MESI.M
WHERE PRENOTAZIONI.CANCL Is Null AND PRENOTAZIONI.AAAA="2022"
GROUP BY MESI.MM, MESI.MESE
WITH a where AAAA dont retrieve all month, i my case i need to show also month with zero result
You do not have the required permissions to view the files attached to this post.

User avatar
sal21
PlatinumLounger
Posts: 4354
Joined: 26 Apr 2010, 17:36

last post

Post by sal21 »

without where AAAA

This post moved to here from a separate topic to provide context. StuartR
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78455
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: WHY dont show all month with where

Post by HansV »

This is because your WHERE-condition requires records in PRENOTAZIONI to exist. Try this:

SELECT MESI.MM, MESI.MESE, Q.CONTA FROM MESI LEFT JOIN (SELECT MM, Count(IDTIP) AS CONTA FROM PRENOTAZIONI WHERE CANCL Is Null AND AAAA="2022" GROUP BY MM) AS Q ON MESI.MM = Q.MM ORDER BY MESI.MM
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4354
Joined: 26 Apr 2010, 17:36

Re: WHY dont show all month with where

Post by sal21 »

HansV wrote:
22 Jul 2022, 10:56
This is because your WHERE-condition requires records in PRENOTAZIONI to exist. Try this:

SELECT MESI.MM, MESI.MESE, Q.CONTA FROM MESI LEFT JOIN (SELECT MM, Count(IDTIP) AS CONTA FROM PRENOTAZIONI WHERE CANCL Is Null AND AAAA="2022" GROUP BY MM) AS Q ON MESI.MM = Q.MM ORDER BY MESI.MM
TKS bro.
but i need the result in the attached image ...

NOTE:
ANNO=2022
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78455
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: WHY dont show all month with where

Post by HansV »

Please attach a sample database (zipped)
Best wishes,
Hans

User avatar
Gasman
2StarLounger
Posts: 103
Joined: 22 Feb 2022, 09:04

Re: WHY dont show all month with where

Post by Gasman »

MM is text in one table and Number in another? :sad:
Using Access 2007/2019.
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
Please, please use code tags when posting code snippets, click the </>icon.
Debug.Print is your lifesaver.

User avatar
sal21
PlatinumLounger
Posts: 4354
Joined: 26 Apr 2010, 17:36

Re: WHY dont show all month with where

Post by sal21 »

HansV wrote:
22 Jul 2022, 13:53
Please attach a sample database (zipped)
Attached in last post

User avatar
sal21
PlatinumLounger
Posts: 4354
Joined: 26 Apr 2010, 17:36

Re: WHY dont show all month with where

Post by sal21 »

Gasman wrote:
22 Jul 2022, 14:20
MM is text in one table and Number in another? :sad:
yes but you can use also M

User avatar
HansV
Administrator
Posts: 78455
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: WHY dont show all month with where

Post by HansV »

SELECT MESI.MM, MESI.MESE, IIf(Q.CONTA Is Null,0,Q.CONTA) FROM MESI LEFT JOIN (SELECT MM, Count(IDTIP) AS CONTA FROM PRENOTAZIONI WHERE CANCL Is Null AND AAAA="2022" GROUP BY MM) AS Q ON MESI.M = Q.MM ORDER BY MESI.MM
Best wishes,
Hans

User avatar
Gasman
2StarLounger
Posts: 103
Joined: 22 Feb 2022, 09:04

Re: WHY dont show all month with where

Post by Gasman »

yes but you can use also M
Oh yes, that makes so much more sense. :sad:

So why is MM linked to MM and not M ?
Using Access 2007/2019.
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
Please, please use code tags when posting code snippets, click the </>icon.
Debug.Print is your lifesaver.

User avatar
sal21
PlatinumLounger
Posts: 4354
Joined: 26 Apr 2010, 17:36

Re: WHY dont show all month with where

Post by sal21 »

Gasman wrote:
22 Jul 2022, 15:10
yes but you can use also M
Oh yes, that makes so much more sense. :sad:

So why is MM linked to MM and not M ?
I need to use M or MM, with different property, in other part of code

User avatar
sal21
PlatinumLounger
Posts: 4354
Joined: 26 Apr 2010, 17:36

Re: WHY dont show all month with where

Post by sal21 »

HansV wrote:
22 Jul 2022, 14:53
SELECT MESI.MM, MESI.MESE, IIf(Q.CONTA Is Null,0,Q.CONTA) FROM MESI LEFT JOIN (SELECT MM, Count(IDTIP) AS CONTA FROM PRENOTAZIONI WHERE CANCL Is Null AND AAAA="2022" GROUP BY MM) AS Q ON MESI.M = Q.MM ORDER BY MESI.MM
AS USUAL EXCELLENT!
Tks.

User avatar
sal21
PlatinumLounger
Posts: 4354
Joined: 26 Apr 2010, 17:36

Re: WHY dont show all month with where

Post by sal21 »

HansV wrote:
22 Jul 2022, 14:53
SELECT MESI.MM, MESI.MESE, IIf(Q.CONTA Is Null,0,Q.CONTA) FROM MESI LEFT JOIN (SELECT MM, Count(IDTIP) AS CONTA FROM PRENOTAZIONI WHERE CANCL Is Null AND AAAA="2022" GROUP BY MM) AS Q ON MESI.M = Q.MM ORDER BY MESI.MM
OPS...

i need to add also a join FROM ANAGRAFICA INNER JOIN PRENOTAZIONI ON ANAGRAFICA.IDCLI=PRENOTAZIONI.IDCLI

new db attached
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78455
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: WHY dont show all month with where

Post by HansV »

Do you need to return any fields from ANAGRAFICA in the query?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4354
Joined: 26 Apr 2010, 17:36

Re: WHY dont show all month with where

Post by sal21 »

HansV wrote:
30 Jul 2022, 09:32
Do you need to return any fields from ANAGRAFICA in the query?
yes!

User avatar
HansV
Administrator
Posts: 78455
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: WHY dont show all month with where

Post by HansV »

Which ones?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4354
Joined: 26 Apr 2010, 17:36

Re: WHY dont show all month with where

Post by sal21 »

HansV wrote:
30 Jul 2022, 10:35
Which ones?
Sorry...
no.
is simple...i need the same result in the image attached but with the addition of this

...JOIN PRENOTAZIONI ON ANAGRAFICA.IDCLI=PRENOTAZIONI.IDCLI...

to the exists query:

SELECT MESI.MM, MESI.MESE, IIf(Q.CONTA Is Null,0,Q.CONTA) FROM MESI LEFT JOIN (SELECT MM, Count(IDTIP) AS CONTA FROM PRENOTAZIONI WHERE CANCL Is Null AND AAAA="2022" GROUP BY MM) AS Q ON MESI.M = Q.MM ORDER BY MESI.MM
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78455
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: WHY dont show all month with where

Post by HansV »

What's the point of adding ANAGRAFICA if you don't want to show any field from that table?
Best wishes,
Hans