AmitDiwan has Published 10744 Articles

MySQL Stored Procedure to update records with certain condition?

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 07:01:43

1K+ Views

For this, you can use the UPDATE command along with the WHERE clause in a PROCEDURE. Let us first create a table −mysql> create table DemoTable    -> (    -> Id int,    -> FirstName varchar(20),    -> LastName varchar(20)    -> ); Query OK, 0 rows affected (0.56 ... Read More

JavaScript Array find() function

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 07:00:14

362 Views

The find() method of JavaScript is used to return the first elements value in an array, if the condition is passed, otherwise the return value is undefined. The syntax is as follows −array.find(function(val, index, arr), thisValue)Here, function is a function with val, which is the value of the current element. ... Read More

What would happen if we insert empty values in a table with a column set as type TIMESTAMP CURRENT_TIMESTAMP?

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 06:58:41

277 Views

If we will insert nothing in the INSERT statement, then for timestamp type, it would insert the current date-time. Let us first create a table −mysql> create table DemoTable    -> (    -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> UserLoginDate timestamp default current_timestamp    -> ); ... Read More

Sort items in MySQL with dots?

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 06:56:06

157 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Value varchar(20)    -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('20'); Query OK, 1 row affected (0.14 sec) mysql> insert into ... Read More

The easiest way to insert date records in MySQL?

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 06:37:37

238 Views

Use the STR_TO_DATE() method to insert date records as in the below syntax −select str_to_date(yourColumnName, '%b %Y') from yourTableName;Let us first create a table −mysql> create table DemoTable    -> (    -> JoiningYear varchar(20)    -> ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table ... Read More

Implement MySQL REGEXP to fetch records with . and numbers

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 06:33:48

129 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Version varchar(20)    -> ); Query OK, 0 rows affected (0.77 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('1.0.0'); Query OK, 1 row affected (0.21 sec) mysql> insert into ... Read More

MySQL Query to set currency records

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 06:31:26

263 Views

Use FORMAT() in MySQL to display currency records and display them in the correct form. Let us first create a table −mysql> create table DemoTable    -> (    -> Amount DECIMAL(15, 4)    -> ); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert ... Read More

MySQL query to display only 15 words from the left?

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 06:29:59

84 Views

For this, use LEFT in MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> Title text    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Java database connectivity to MySQL ... Read More

Replacing numbers on a comma delimited result with MySQL?

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 06:27:59

245 Views

For this, use CASE statement along with FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable1629     -> (     -> Month varchar(100)     -> ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command.mysql> insert into DemoTable1629 values('2, ... Read More

Create MySQL datetime column with default 0000-00-00?

AmitDiwan

AmitDiwan

Updated on 17-Dec-2019 06:27:12

797 Views

To set default, you can use the DEFAULT keyword in MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeName varchar(20),    -> EmployeeJoiningDate datetime default '0000-00-00 00:00:00'    -> )ENGINE=MyISAM, AUTO_INCREMENT=100; Query OK, ... Read More

Advertisements