ifnull

Unexpected BLOB results with MySQL testing NULL variable with IFNULL, COALESCE

耗尽温柔 提交于 2020-06-17 09:48:06
问题 In trying to test whether a variable has been defined, I discovered that the IF, IFNULL, and COALESCE statements return simply BLOB rather than the value I expected when (a) the variable has not been defined or (b) it has been explicitly set to NULL before being assigned a value in the session. I've verified this in MySQL versions 5.7 and 8.0. SELECT IF(@p IS NULL, 'is null', 'not null'); # 'is null' SELECT IF(@p IS NULL, 'is null', @p); # BLOB SELECT IFNULL(@p, 'is null'); # BLOB SELECT

symfony2 doctrine select IFNULL

故事扮演 提交于 2020-01-02 01:02:27
问题 Ok i have this code: SELECT IFNULL(s2.id,s1.id) AS effectiveID, IFNULL(s2.status, s1.status) AS effectiveStatus, IFNULL(s2.user_id, s1.user_id) as effectiveUser, IFNULL(s2.likes_count, s1.likes_count) as effectiveLikesCount FROM statuses AS s1 LEFT JOIN statuses AS s2 ON s2.id = s1.shared_from_id WHERE s1.user_id = 4310 ORDER BY effectiveID DESC LIMIT 15 And i need to rewrite it to querybuilder. Something like that? $fields = array('IFNULL(s2.id,s1.id) AS effectiveID','IFNULL(s2.status, s1

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

倖福魔咒の 提交于 2019-12-25 16:24:31
问题 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) 回答1: You can also use the standard COALESCE keyword, which allows you to pass it multiple parameters: SELECT COALESCE(columna, columnb, ..., columnz) FROM mytable COALESCE keyword documentation 回答2: just found out: SELECT nvl(columna, columnb) FROM mytable http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions105.htm 来源: https:/

Include null results in group_concat

帅比萌擦擦* 提交于 2019-12-20 03:37:13
问题 I have two tables like this profile_answers +---------+------------+ | id | class_name | +---------+------------+ | 1 | Class 1 | | 2 | Class 2 | | 3 | Class 1 | +---------+------------+ educations +---------+--------------------+------------+ | id | profile_answers_id | sample | +---------+--------------------+------------+ | 1 | 1 | 1234 | | 2 | 1 | 2334 | | 3 | 1 | 3434 | +---------+------------+--------------------+ I ran the query, select educations.profile_answer_id, GROUP_CONCAT

mysql how to find if at least one row from cross reference table is null or criteria

冷暖自知 提交于 2019-12-13 08:29:21
问题 i have trouble with mysql, i dont find the way to do it maybe i dont know the good mysql keyword mysql5 +----------+------------+----------+ | ID | FOREIGNKEY | TRAINER | +----------+------------+----------+ | ... | ... | ... | | 475 | 254 | NULL | | 476 | 254 | NULL | | 477 | 254 | NULL | | 478 | 286 | NULL | | 479 | 286 | FREE | | 480 | 286 | FREE | | 481 | 401 | FREE | | 482 | 401 | 1 | | 483 | 401 | FREE | | 484 | 405 | NULL | | 485 | 405 | 1 | | 486 | 405 | 5 | | 487 | 405 | FREE | | 488

MySQL IFNULL() with multiple tables isn't working

若如初见. 提交于 2019-12-11 20:39:31
问题 I'm using this query in my code, but it doesn't give me a result $query = sprintf("SELECT s.day, s.hour, h.name hostName FROM schedule s, host h WHERE dag IN (SELECT day FROM schedule WHERE showId = %s ORDER BY day, hour) AND s.hostId = h.id, AND s.showId = %s ORDER BY day, hour", mysqli_real_escape_string($con, $id), mysqli_real_escape_string($con, $id)); I know it's because s.hostId can be NULL. I've found the IFNULL()-method, and used it like this, but that didn't work. SELECT s.day, s

symfony2 doctrine select IFNULL

馋奶兔 提交于 2019-12-05 00:57:30
Ok i have this code: SELECT IFNULL(s2.id,s1.id) AS effectiveID, IFNULL(s2.status, s1.status) AS effectiveStatus, IFNULL(s2.user_id, s1.user_id) as effectiveUser, IFNULL(s2.likes_count, s1.likes_count) as effectiveLikesCount FROM statuses AS s1 LEFT JOIN statuses AS s2 ON s2.id = s1.shared_from_id WHERE s1.user_id = 4310 ORDER BY effectiveID DESC LIMIT 15 And i need to rewrite it to querybuilder. Something like that? $fields = array('IFNULL(s2.id,s1.id) AS effectiveID','IFNULL(s2.status, s1.status) AS effectiveStatus', 'IFNULL(s2.user_id, s1.user_id) as effectiveUser','IFNULL(s2.likes_count, s1

mysql IFNULL ELSE

不问归期 提交于 2019-12-03 18:38:08
问题 I have a select statement where I want to make select conditional like this IFNULL(field_a,field_a,feild_b) so that it checks field a if a is null then the select would be field b is that possible ? 回答1: Use COALESCE: SELECT COALESCE(field_a, field_b) COALESCE is an ANSI standard function that returns the first non-null value from the list of columns specified, processing the columns from left to right. So in the example, if field_a is null, field_b value will be displayed. However, this

cakePHP 3 Query ifnull

让人想犯罪 __ 提交于 2019-12-02 13:25:01
问题 I wonder what would be the best way to prevent null results in a ResultSet. I'm on cake 3.5.13 and I'm using cases, like: private function addCase($isforeign, $source) { $query = $this->Sales->find(); return $query->newExpr() ->addCase( $query->newExpr()->add([ 'Sales.isforeign' => $isforeign, 'Sales.source' => $source ]), 1, 'integer'); } I then put the return of my addCase function in (..) 'sourcenationalcount' => $query->func()->sum($this->addCase(0, 1)), (..) Now it is possible that

Include null results in group_concat

隐身守侯 提交于 2019-12-02 06:49:48
I have two tables like this profile_answers +---------+------------+ | id | class_name | +---------+------------+ | 1 | Class 1 | | 2 | Class 2 | | 3 | Class 1 | +---------+------------+ educations +---------+--------------------+------------+ | id | profile_answers_id | sample | +---------+--------------------+------------+ | 1 | 1 | 1234 | | 2 | 1 | 2334 | | 3 | 1 | 3434 | +---------+------------+--------------------+ I ran the query, select educations.profile_answer_id, GROUP_CONCAT(educations.sample) from educations LEFT JOIN profile_answers ON educations.profile_answers_id = profile