Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I select from table by uuid in mysql

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.

like image 229
Boss Yoon Avatar asked Mar 24 '15 02:03

Boss Yoon


People also ask

How to query info from UUID column in MySQL?

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.

Can two UUIDs be the same in MySQL?

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 –

How to create a column UID of type text in MySQL?

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 –

What are UUIDs and how to use them?

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 –


1 Answers

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

like image 82
lomdalf Avatar answered Nov 10 '22 20:11

lomdalf