Mysql Query doesn't work as expected (with left joins)

Mysql Query doesn't work as expected (with left joins)

Hello mysql and sql experts

Hello mysql and sql experts

I have a problem with my query.

I have 3 tables (As you can see in the images below)

One table for the event One table for the user account And one table where the event table and user account table is linked to (Teilnehmer table)

When a user Sign up to a event, the EventID and also the UserID will be stored in the Teilnehmer table.

That works fine.

Now the problem is, I've created a query which should only return the events, which are Enabled = 1, the user didn't Sign up to and the Count of FK_eventID is < Event.Anzahl

but that doesn't work.

The Count and Enabled join works, but although the user sign up to a event, the event will still be returned

can anybody see my problem ?

SELECT v.ID, 
       v.NameVeranstaltung, 
       v.Datum, 
       v.Uhrzeit, 
       v.Anzahl, 
       v.Beschreibung, 
       v.Enabled, 
       Count(t.FK_eventID) 
FROM   Veranstaltung AS v 
       LEFT JOIN Teilnehmer AS t 
              ON t.FK_eventID = v.ID 
       LEFT JOIN Users AS u 
              ON t.FK_userID = 17 
WHERE  v.Enabled = 1 
GROUP  BY t.FK_eventID, 
          v.NameVeranstaltung 
HAVING Count(t.FK_eventID) < v.Anzahl 


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

What are the differences between Standard SQL and Transact-SQL?

In this article, we'll explain syntax differences between standard SQL and the Transact-SQL language dedicated to interacting with the SQL

SQL Full Course - SQL Tutorial For Beginners - MySQL Essentials - SQL Training

This SQL Full Course video will cover all the topics of SQL starting from scratch. This video is great for beginners who want to learn SQL and for advanced people to brush up their skills.