duangong0690 2019-03-14 10:42
浏览 51

哪里是null或不是equalent值不返回mysqli中的记录

I am trying to fetch the records from two tables.

1 - tokens 2 - transactions

In both tables there is same column user_id and tokens table has transaction_id. I am trying to get all transactions which has relation with token. I am trying following

select sum(`amount`) as aggregate 
from `tokens` 
where `user_id` in (15, 713, 49, 58, 60) 
and exists 
    (select * 
    from `transactions` 
    where `tokens`.`transaction_id` = `transactions`.`id` 
    and (`custom` != 'BB' or `custom` is null)
    )

When I change operator in my query like ``customis not null then I am getting the record, but not means query will show the record of 'BB'.

I have searched about it and found a good sentence from this thread

NULL Cannot be compared to any value using the comparison operators. NULL = NULL is false. Null is not a value. The IS operator is specially designed to handle NULL comparisons.

So in custom I have only one value which is BB and another is NULL.
My above query is not working.

Can someone kindly guide me how can I resolve the issue?

  • 写回答

0条回答 默认 最新

    报告相同问题?