How to retrieve the columns based on the UUID - mysql

In my application database the table is called Customer which has fields:
CUSTOMER TABLE
cust_id
cust_name
cust_age
In above table cust_id data type is binary and UUID has been inserted into the table :
Insert statement looks like this:
INSERT INTO Customer VALUES ('444d264e-9024-11e4-968c-b82a72ad8ef8','swify',41);
The data has been inserted successfully . Similarly in this fashion i have inserted multiple records into the DB
Now i want to retrieve a particular record from the DB Usin select statement.
I tried this approach but it's giving no rows
SELECT * FROM Customer WHERE cust_id='444d264e-9024-11e4-968c-b82a72ad8ef8';
Hence, My question is how can i retrieve a record based on the UUID values;

Try this:
SELECT * FROM Customer WHERE cust_id LIKE '444d264e-9024-11e4-968c-b82a72ad8ef8';

Related

How to get the first 4 rows of each record in table and append to the select instead rather than rows?

I have two tables:
documents table
audits table.
audits table is a polymorphic table and has auditable_type and auditable_id which is linked to the id of documents table. audits table also has event and new_values column.
Here's the table schema.
documents table has user_defined_field JSON column.
My goal is I want to get the first 4 values of the status field in user_defined_field JSON column. There will be a column in the report of the web app to display the 1st Status, 2nd Status, 3rd Status, 4th Status.
So basically, it's like the documents table is join to audits table and should get the first 4 record of the document id and display it in the SQL select as status_1, status_2, status_3, and status_4
Thank you.

Update MySQL table with values from another table

I have a MySQL database and I need to update table rows with values from another table. For example in one table there is a list of addresses which are stored for a specific customer. There is one address entry per customer and this address ID is stored in the Customers table in each customer entry under "address_id" column. I would like to know if it's possible to run a query which will update a list of addresses with the id's of the customers. So for each address row which id is found in customer row should have customer id in the specific column. Thanks in advance!

Is there any feature in MySQL to perform query only on last inserted row in a table?

I need to validate the last inserted row in a table every time using some constraints given by the user on a particular column in that table( Ex: age > 50...etc.).
I thought of using a temporary table to insert the row in both of my temporary table and my normal table. After then, I'll use query like Select * from tb_name USER_CONSTRAINTS [ Ex: select * from student where age>50 ] on temporary table. If the result is not null, then the last row satisfies the user constraint else it fails. After I'll delete the last added row from the temporary table and repeat the process for next row.
I don't know if this way is good or bad or is there some other efficient way to do this?
Edit:
The table has 5 columns
stud_id,
subject_id,
age,
dob,
marks
Here stud_id and subject_id act as foreign keys to two tables tbl_student and tbl_subject

capture oracles's (sequence.nexval) value in a column during data flow

I am doing an insert from SQL server table to Oracle table, which has a sequence for its identity column. I have used OLDDB command as my destination and used the following query for insert into oracle table
Insert into tablename (id, col1,col2....) values (seq.nextval,?,?,...)
I mapped all parameters to source columns and it works like a charm including sequence generation for identity column.
My other requirement is that the sequence that was generated in the first table has to be mapped with another table for foreign key relation, as follows:
table 1
emp table with columns
empid ----------- generated from sequence
name suffix
table 2
empinfo table with column
empinfoid ---- generated from sequence
empid ----- id that was generated in table 1.
address
edulevel
Since I do not have any others common keys between these two tables, I cannot have lookup and pull empid from table 1 to table 2.
How can I insert empid (generated from sequence) into both tables in parallel? I tried with oledb command out parameter, but wasn't successful as the Oracle connection is unable to find output params.
Provided you run both insert statements are in the same session, you insert seq.currval in table2.

SQL: flavours of INSERT INTO

(MySQL) I am trying to migrate a "subscription" table into 3 new tables: "product", "subscription", "actual" where "actual" is the name of the actual product, say, newsletter. The subscription has a FK reference to product and the actual has FK reference into subscription.
I know the INSERT INTO SELECT statement can copy data probably from many table to one; is there a statement to do the opposite, one to many tables for my case?
I'm not aware of an SQL statement that will do what you want. Just do several INSERT INTO SELECTs one after the other. It may be faster to do them one at a time anyway.
I think you can use three seperate insert into select statements. First you convert the product table, then the subscription where you can use an embedded select to find the id in the product table:
insert into subscription (some_column, FK_id,...)
select something, (select id from product where <your where clause>),...
and finally convert the actual table using an embedded select to get the id from the subscription table.