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
2 answers

run query if row count = 0

I have created 3 tables: playlist, tracklist, & xmlexport, which I use for storing my playlists. To keep from duplicating any of the items in the playlist, I use a tracklist that I insert from the playlist & I insert the top row of my tracklist into…
drs
  • 45
  • 1
  • 6
0
votes
1 answer

Mysql IFNULL working only once in a multiple SELECT query

I'm trying to build a month graphic using a MySQL query. I'm checking how many rows there are in a table for each month in a single query using the UNION command. Example with 3 months bellow: $query = "SELECT IFNULL((SELECT SUM(score) FROM…
DanielFox
  • 675
  • 2
  • 9
  • 18
0
votes
2 answers

oracle equivalent of mysql ifnull (no case, no if)

I am looking for a quick way to do SELECT IFNULL(columna, columnb) FROM mytable (I have dozens of columns and don't want to write a case for each of them)
NotGaeL
  • 8,344
  • 5
  • 40
  • 70
0
votes
2 answers

Using IFNULL function mysql to set null to zero

I have tables on my database with the following schema: customers (customerID: integer, fName: string, lName: string) items (itemID: integer, description: string, price: integer) orders (orderID: integer, itemID: integer, aID: integer,…
mar
  • 111
  • 2
  • 4
  • 10
0
votes
1 answer

IFNULL Function is Not Working in MySQL Query

I want operator by Grand Total. but IFNULL function is not working. SELECT IFNULL(op.operator_name, "Grand Total") AS operator, SUM(re.amount) AS amount FROM mobile_db.recharge re INNER JOIN mobile_db.operator op ON re.operator_id =…
Shihab
  • 83
  • 1
  • 3
  • 10
0
votes
2 answers

Fill in blank data if no result found in mysql query

I have a query that is checking data for 5 review sites and returning the site_id, review_count & review_average. If there is no data for a review site then I want to return 0 for the count & average. Is this possible to do in a mysql…
626
  • 1,159
  • 2
  • 16
  • 27
0
votes
0 answers

MySQL - Calculation IFNULL value being returned instead of 0.00

I have added a percentage calculation (%_SOLD - SOLD as a percentage of FOUND - line 3 below) to my query which is working to an extent but returning the IFNULL value instead of 0.00 when SOLD is being returned as NULL. IFNULL(ROUND((SUM(CASE WHEN…
the_gimlet
  • 183
  • 1
  • 2
  • 7
0
votes
1 answer

mysql IFNULL syntax i don't know what's wrong

I'm going to use IFNULL check in my select query I want to execute like this, when sum is null then print 0 This is my whole query SELECT IFNULL(SELECT SUM(TOT_SALES_PRICE) FROM TB_DEALER_SALES_MNG WHERE DEALER_SEQ = 7 AND…
0
votes
1 answer

mysql same row different column ref.(ifnull check)

I want IFNULL check in same row, but different column. This is my sql example. SELECT a.CONTACT_SEQ, 'TEST' AS MEMO, NOW() AS REG_DATE, a.USER_ID, a.NAME, a.CONTACT_NUM AS PHONE_NUM, (SELECT COUNT(*) FROM TB_CONTACT AS…
0
votes
1 answer

Left join on last record (simple discussion board with topics, last posts and users)

I'm trying to make a simple discussion board and as a result I need topics titles with their authors and authors of topics last posts. So far I have this SELECT `t`.`id`, `t`.`title`, `t`.`date` as theme_date, `u`.`id` as user_id, …
Goldie
  • 1,570
  • 5
  • 21
  • 33
0
votes
0 answers

MySQL : Ambiguous Column with ifnull rollup

I'm getting this error when i want to run a View, but I don't know why: [23000][1052] Column 'name' in field list is ambiguous Query: create view prefix_group_rating AS SELECT r.rating_date …
elarichi.y
  • 57
  • 8
0
votes
2 answers

How to test subqueries and return first non null result in MySQL?

I have a number of queries that contain multiple columns and I would like to run a single query to test them in order until one subquery returns results. I have found that a COALESCE statement only allows you to use and return a single column per…
somecallmemike
  • 441
  • 1
  • 8
  • 19
0
votes
1 answer

LOAD DATA INFILE should fill up empty values with specific content

LOAD DATA INFILE should fill up only empty values with a specific content. CSV: Value1, Value2 -------------- 1 123345 2 3 678901 EXPECTED RESULT: Value1, Value2 -------------- 1 123345 2 k0000123345 3 …
Thomas B
  • 65
  • 7
0
votes
1 answer

MySql first result before and after result set

I've got this awful query where I use IFNULL to determine whether there is a result before and a result after my result set. The result set is determined by a period in time, see may 5th till may 10th. This period of time is visualised in my…
Mike de Klerk
  • 11,906
  • 8
  • 54
  • 76
0
votes
1 answer

IfNull function in mysql doesnt seem to work for me

IfNull function in mysql doesnt seem to work for me.... When i executed this query select t1.dAccHeader_id,t1.dAccHeaderName,t1.dAccHeaderAcronym, t2.dDesignationName as incharge1, t3.dDesignationName as incharge2,t4.dDesignationName as…
M Y T H
  • 97
  • 2
  • 7