Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a known problem where MySQL does not return all data?

I made a database and a table in it with different types of cars, and in the table, there are two with the brand Toyota among other brands.
I then tried to search the entire table using SELECT * FROM Car WHERE Make='Toyota'; but only one row appeared.

This is the code with the information that was brought up:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The problem is that your query tries to match exactly 6 characters "Toyota", whereas your input samples may have hidden spaces. If you want this query to work, you either check that there are no leading and trailing spaces or use one of the following solutions:

Option 1: the TRIM function removes leading and trailing spaces

SELECT * 
FROM Car 
WHERE TRIM(Make) = 'Toyota';

Option 2: the LIKE statement will allow you to get any string that has the word "Toyota" in it (% is a wildcard for "any string"):

SELECT * 
FROM Car 
WHERE Make LIKE '%Toyota%';

Note: These queries will work with the MySQL DBMS. If you have a different DBMS, add it in your problem statement as tag.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading