I have this table:
CREATE TABLE `country` (
`name` VARCHAR(60) NOT NULL,
`code` VARCHAR(3) UNIQUE NOT NULL,
PRIMARY KEY (`code`)
);
As you can see the primary key of this table is the word code
When I try to select a specific code in this table, that is 2 characters long, it cannot find anything.
On the other hand, when I select a 3 characters long code like this:
select * from `country` where `code` = "TZA";
I get the result I want
I searched for my variable in the table (for example the code "AL") and it appears to be registered.
Why is this happening and how could I make it work?
Thank you in advance!
I am importing my data from a csv file that looks like this:
LOAD DATA LOCAL INFILE 'path_to_file\\countries.csv'
INTO TABLE `country`
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
(`name`, `code`);
I have tried selecting with a space in the end of the code
and on the front of it:
select * from `country` where `code` = 'AL ';
select * from `country` where `code` = ' AL';
But they output nothing
CodePudding user response:
The real solution is:
When importing this CSV file you should use:
LOAD DATA LOCAL INFILE 'path_to_file\\countries.csv'
INTO TABLE `country`
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
IGNORE 1 ROWS
(`name`, `code`);
Because your lines seems to be terminated the way Windows terminates lines.