Questions tagged [ifnull]

This tag refers to the process of determining whether or not a particular object is null, and then running certain code based off of that condition.

Use this tag for questions related to running certain code depending on whether or not one or more objects is null.

161 questions
0
votes
1 answer

MySql ifnull and count bug?

MySql version: 5.7.18-15-log, My classmate asked a question: SELECT COUNT(1) Counts, IFNULL((SELECT SUM(c.RealMoney) FROM PayRecord c WHERE a.id=c.orderid), 0) money FROM `Order` a WHERE a.UserId ='not exists user id'; he got a result :…
youbl
  • 134
  • 1
  • 11
0
votes
1 answer

Where clause using alias column with IF and IFNULL

I have an mysql query like below: SELECT sppt_ticket.*, IF(sppt_read_support_ticket.ID_aks_user IS NULL,'N', 'Y') AS `read_status`, IFNULL(readcomment.total_comment, 0) AS unread_comment FROM sppt_ticket …
Yosafat Ksatria
  • 133
  • 1
  • 1
  • 14
0
votes
2 answers

MYSQL one big left outer join or 3 left outer joins same tables?

I'm not sure how to join two tables onto my main query. The two tables that determine the accountnumber join to each of the 3 main tables for different situations. I'm trying to determine the accountnumber based on three things. An accountnumber…
0
votes
3 answers

MySQL WHERE IN condition with IFNULL function

I have problem with IFNULL function used within WHERE IN condition: SELECT provider_id FROM provider WHERE provider_id IN ( IFNULL("131, 132",'999') ) I tried all quoting alternatives like: SELECT provider_id FROM provider WHERE provider_id IN (…
lman
  • 9
  • 1
  • 2
0
votes
4 answers

mysql ifnull where

i need such query select * from t where field=ifnull(:param, field) 'it not work's so if param=NULL i have select * from t where field is NULL but if param =4 i have select * from t where field=4
kusanagi
  • 14,296
  • 20
  • 86
  • 111
0
votes
0 answers

Filling nulls with expression

ID | Seq | Status | ------+-------+-----+ 1 | 1 | OK | 1 | 2 | Fail | 1 | 3 | NULL | 1 | 4 | NULL | I have the data above that I am working with. I would like there to be no nulls in the status bar. Instead, if something has…
0
votes
0 answers

Datetime query not working after conversion from MySQL 5.5 to AWS Aurora

I have migrated a MySQL 5.5 database over to AWS Aurora and have both databases working as expected with one exception. A set of stored procedures that utilise COALESCE and IFNULL in the WHERE clause are not behaving as expected for DATETIME…
0
votes
1 answer

Add a 0 if there is no SUM for a given date in MySQL?

I been trying to make this one work, but can't find a solution. I want to grab the SUM of a row for a given date, and if there is no entry for that date, return a 0. I tried using IFNULL() but can't make it work. My query grabs the data for the last…
JordanBelf
  • 3,208
  • 9
  • 47
  • 80
0
votes
2 answers

Sql query, table /w double rows, join on IFNULL function - table join on tiself with variable column

Hi we have a table that looks like this (call it table A). It contains both rows if parent and children data. I need to get rows like below containing both the item_id and the parent_item_id if it exists (otherwise the item_id). Now I need to join…
snh_nl
  • 2,877
  • 6
  • 32
  • 62
0
votes
1 answer

MySQL Sum of Field Always Show NULL

I have a problem to sum of field that always show null, I already tried all of these MySQL query, (SUM(IFNULL(topup_amount,0))) AS total, SUM(topup_amount) AS total2, COALESCE(SUM(topup_amount),110), IFNULL(SUM(topup_amount),…
Bobby
  • 253
  • 1
  • 4
  • 20
0
votes
1 answer

SQL query take 60 seconds to complete

I have this query for a table with 14 thousands rows... took forever to complete the output. Here is the code: $query="SELECT j6.Name, j.id, SUM(j6.pts) + IFNULL(j.pts, 0) AS total FROM joueurs2006 j6 LEFT OUTER JOIN joueurs j …
0
votes
1 answer

SQL COUNT(*) return 0 IFNULL with WHERE clauses and GROUP_BY on same table

The result should return a row with the date even if the count is null. SELECT DATE_FORMAT(created_date, '%Y-%m') AS date, COUNT(*) AS total FROM mytable WHERE created_date BETWEEN :startDate AND :endDate AND condition = :condition GROUP BY…
mchev
  • 713
  • 1
  • 8
  • 22
0
votes
1 answer

SQL Query, Subquery won't return data

Problem: My Query returns NULL Potential issues: Subquery formatted wrong and only works if some data I want to sort out is in the dataset. Example of today's code: SELECT production_order ,SUM(total_working_time_h) - (SELECT…
0
votes
0 answers

Adding an IFNULL condition for a count

I am having an issue getting a record produced if my count = 0. Basically my query is counting logons based on some criteria, but if there has never been a logon for a specific customerID I still want it to show as 0. I have tried IFNULL on the…
JoelG
  • 37
  • 1
  • 6
0
votes
1 answer

Can't increment an empty set with mysql

I'm trying to write an update that will increment the value of auth_id; however, if there is no value, I'd like to set it to 1. I can't even get the select to give me a 0 value to increment. mysql> describe…
SaintHax
  • 1,875
  • 11
  • 16