AmitDiwan has Published 10744 Articles

Get field value and convert a particular character from it to uppercase with MySQL

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 07:04:08

132 Views

Let us first create a table −mysql> create table DemoTable1897    (    Name varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1897 values('john'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1897 values('Chris'); Query ... Read More

Get only a single value from a specific MySQL row?

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 07:02:32

2K+ Views

For this, use SELECT INTO variable with where clause. Let us first create a table −mysql> create table DemoTable1896    (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(20),    StudentMarks int    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using ... Read More

What to assign to a MySQL column that must not be empty?

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 06:58:48

399 Views

Define with NOT NULL, if a column must not be empty. Let us first create a table with one of the columns as NOT NULL −mysql> create table DemoTable1895    (    Id int NOT NULL,    FirstName varchar(20),    LastName varchar(20) NOT NULL    ); Query OK, 0 rows ... Read More

Set a MySQL field with the current date (UNIX_TIMESTAMP(now))

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 06:57:19

578 Views

For this, use unix_timestamp(). Let us first create a table −mysql> create table DemoTable1894    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    DueTime int    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1894 values(); Query ... Read More

Can you allow a regex match in a MySQL Select statement?

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 06:51:28

169 Views

Yes, we can do regex match in a select statement −select yourColumnName from yourTableName where yourColumnName regexp '^yourValue';Let us first create a table −mysql> create table DemoTable1892    (    FirstName varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> ... Read More

MySQL Stored procedure to declare two values and perform mathematical operation

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 06:50:21

909 Views

Let us first create a stored procedure −mysql> delimiter // mysql> create procedure declare_demo_sp()    begin    declare Value1 int;    declare Value2 int;    set Value1=100;    set Value2=2000;    select Value1, Value2, Value1*Value2 as MultiplicationResult;    end    // Query OK, 0 rows affected (0.00 sec) mysql> delimiter ... Read More

Check if MySQL entry exists and if it does, how to overwrite other columns?

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 06:48:48

246 Views

For this, use INSERT ON DUPLICATE KEY UPDATE command. Let us first create a table −mysql> create table DemoTable1891    (    FirstName varchar(20),    UNIQUE KEY(FirstName)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1891 values('Chris') on ... Read More

Select data and set value to boolean based on timestamp column in MySQL

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 06:47:30

394 Views

For this, use IF(). Let us first see the current date −mysql> select curdate(); +------------+ | curdate()  | +------------+ | 2019-12-10 | +------------+ 1 row in set (0.00 sec)Let us first create a table −mysql> create table DemoTable1890    (    DueDate timestamp    ); Query OK, 0 rows affected ... Read More

How to sum current month records in MySQL?

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 06:46:05

968 Views

To sum current month records, use the SUM() and MONTH() function. Let us first create a table −mysql> create table DemoTable1889    (    DueDate date,    Amount int    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1889 ... Read More

MySQL query to update all entries with md5 version of name?

AmitDiwan

AmitDiwan

Updated on 27-Dec-2019 06:43:27

874 Views

For this, you can use MD5(). Let us first create a table −mysql> create table DemoTable1887    (    Password text,    HashPassword text    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1887(Password) values('John@9089'); Query OK, 1 row ... Read More

Advertisements