Search code examples
mysqltextvarchar

Query on "text" field in MySQL not working


I have a MySQL Query that looks something like this,

SELECT dactivityid, saction, resolution FROM supactiv where resolution <> ''

Now this returns results where resolution still has '' values in it. My aim is to only show results, which actually have a valid resolution value and so are not ''. Resolution is a "text" field in MySQL. Is there any way to fix this query so that it respects the condition in the query?


Solution

  • I have created below table and inserted below records and it worked perfectly.

    ------------------------------------------
    
    CREATE TABLE IF NOT EXISTS `supactiv` 
    (
    
        `dactivityid` int(11) NOT NULL AUTO_INCREMENT,
    
        `saction` enum('A','B','C','D') NOT NULL,
    
        `resolution` text NOT NULL,
    
        `createdon` date NOT NULL,
    
        `updatedon` timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP,
    
         PRIMARY KEY (`dactivityid`)
    
    ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
    
    
    ------------------------------------------
    
    INSERT INTO `supactiv` (`dactivityid`, `saction`, `resolution`, `createdon`, `updatedon`)
    
    VALUES (1, 'A', '', '2015-07-02', '2015-07-02 17:51:03'),
    
    (2, 'B', 'test', '2015-07-02', '2015-07-02 17:51:03'),
    
    (3, 'C', '', '2015-07-02', '2015-07-02 17:51:03');
    
    ------------------------------------------
    

    I have created the above table and tried your query it's working absolutely fine. You can check your table type and other aspects.

    Or create table SQL and data SQL so I can check and answer you best of mine.

    Thank you