I want to select some data from database (MySQL) comparing 'Id' Column. And It's type is binary(16) .
So, I write query like this but It's not work. Empty dataset returned. How Can I fix it?
select Id, CompanyName from table1 where Id = 'e4816509-dd01-cf1b-65e3-dc43e2a90a01';
Thank you.
Or, you can use this query with function in MySQL version 8.0 and above. You can see that the employee id having BINARY Data type has the 16 bit digits in the table. Now, to query info from a UUID column from the table, we will apply the function BIN_TO_UUID () that transforms the binary data value to human readable form as follows.
Two UUIDs can never be the same even if the function is run on two different devices. A UUID value in MySQL is a 128-bit number represented as a utf8 string of five hexadecimal numbers separated by a ‘-’. The format is as follows –
We create a column UID of type text using the ALTER statement. Then we use the UPDATE statement to set a UUID value for each row and finally we use the SELECT statement to display the updated table. The output is –
A key point to note about UUIDs is that they are designed such that they are globally unique in space and time. Two UUIDs can never be the same even if the function is run on two different devices. A UUID value in MySQL is a 128-bit number represented as a utf8 string of five hexadecimal numbers separated by a ‘-’. The format is as follows –
I don't know if you still need this. But, here's the query.
select Id, CompanyName from table1 where Id = x'e4816509dd01cf1b65e3dc43e2a90a01';
OR
select Id, CompanyName from table1 where Id = 0xe4816509dd01cf1b65e3dc43e2a90a01;
!!! note that the dashes from the uuid were removed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With