Home > Software design >  MySql query no result
MySql query no result

Time:04-10

When I do the query

select * from departments where dept_name = 'Finance';

I got the following result

why no results?

But I do the query

select * from departments;

I got the result

It does exist

the table departments is created by following:

CREATE TABLE departments (
    dept_no     CHAR(4)         NOT NULL,
    dept_name   VARCHAR(40)     NOT NULL,
    CONSTRAINT pk_departments PRIMARY KEY (dept_no)
);

The version of my MySql is 8.0.28 for Win64 on x86_64 (MySQL Community Server - GPL)

Any idea?

CodePudding user response:

I think there are some spaces in your Finance value, you can check it out by using CHAR_LENGTH():

SELECT
CHAR_LENGTH(dept_name) AS 'character length' 
FROM departments 
WHERE dept_no = 'd002'
  • Related