2

I have sizes table with decimal and non-decimal value so I want to fetch data as per requirement and I have written mysql query for this, but getting empty result even data is present.

Note:I don't want to use LIKE clause

Table:

id      size
1       17X23
2       28.3X39.8 
3       25X39.8
4       28X36

Mysql query:

Select * from sizes where size='28.3X39.8'; // X is uppercase 'X' alphabet I have used to mention width X height

Output: empty result

5
  • We need your tables descriptions to help you Commented Feb 16, 2021 at 16:29
  • @Claus Bönnhoff I am storing widthXheight values which contain decimal and non-decimal value and to represent multiplication symbol I am using X Commented Feb 16, 2021 at 16:31
  • As presented here, your code works as expected: sqlfiddle.com/#!9/dadecc/1 Commented Feb 16, 2021 at 16:31
  • You have a serious data type problem Commented Feb 16, 2021 at 16:46
  • I guess he does not even now which datatype his columns are. Elsewhere he would show us his table description Commented Feb 16, 2021 at 17:34

2 Answers 2

1

could be you have some hidden space

select Select * from sizes where trim(size)='28.3X39.8'; 

or

select Select * from sizes where trim(replace(size,' ',''))='28.3X39.8'; 

or

select Select * from sizes where upper(trim(replace(size,' ','')))=uppper(trim('28.3X39.8')); 
Sign up to request clarification or add additional context in comments.

5 Comments

I tried both queries , still didn't get any output
answer updated with another suggestion too.. anyway which data type is the column size??
varchar data type used, I tried all suggested queries but I am surprised why none of then working
how to do that?
exit and reenter in your ide or db console first .. restart your db service . or restart you server .. .
0

You can try this:

select * from sizes where trim(upper(size))='28.3X39.8';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.