SQL Query to not display null values

Nathan K

I have managed to hack an SQL Query together and it was working until I realised some members in the database have null names due to the plugin we are using removes non-ascii names. I am displaying these stats on my page and having someone with no name doesn't work too well. I know how to not display NULL when using the WHERE clause but i'm not too sure when no WHERE clause is used.

What I have so far -

SELECT player_stats.player_name, COUNT(player_kill.killer) 
FROM player_stats 
LEFT JOIN player_kill ON player_stats.player_id = player_kill.killer  
GROUP BY player_stats.player_name 
HAVING COUNT(player_kill.killer) > 1 
ORDER BY COUNT(player_kill.killer) DESC;
Barmar

The WHERE clause goes between all the JOIN clauses and GROUP BY. If WHERE player_name IS NOT NULL isn't working, the names are probably empty strings, not NULL, so you need to check for that as well.

SELECT s.player_name, COUNT(*) AS count
FROM player_stats AS s
INNER JOIN player_kill AS k ON s.player_id = k.killer  
WHERE s.player_name IS NOT NULL AND s.player_name != ''
GROUP BY s.player_name 
ORDER BY count DESC;

Also, if you don't want to get 0 counts, use INNER JOIN rather than LEFT JOIN.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

SQL query with null values

Select only not null column values and display only that values using sql query

Null values in My SQL query

Query not returning NULL values - SQL

SQL Query not returning Null values

sql query sort but display specific values on top

Find null values returned by SQL query

c# create a sql query with null values

Handling NULL values in an SQL Query that uses SUM

sql query xml values returning NULL

Replacing null values in dynamic pivot sql query

SQL query group by with null values is returning duplicates

Sql query that not return null values in result

How to display only non-null values using an aggregate query?

SQL query to fetch employees with null and not null commission values of a particular department

VBA Code to Paste SQL Query in Excel with NULL values pasted as "NULL"

Single SQL query to tackle NULL and non-NULL values

Dynamic SQL Query to ignore null values based on null value in cell

SQL XML Query/Exist: Looking for null/not null values

SQL query comparing decimal values not matching and returns NULL values

How to do a SQL query with SRFs and display only distinct values?

SQL query to display column values as column name in table

SQL Query is not returning NULL values despite using IFNULL (MySQL)

SQL query should not return rows that contain null values in pivot table

SQL Server Query: Using JOIN to include NULL values

SQL-query order by multiple columns having null values

Treating null values of two records as not equal in SQL query

.NET: How to deal with possible null values in an SQL query?

SQL Server Query to Fill Empty Record with null or 0 Values