AmitDiwan has Published 8358 Articles

Fix MySQL Database Error #1064?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 07:02:02

2K+ Views

The Database Error #1064 may occur due to incorrect syntax. For example, let’s say we are creating the below table −mysql> create table DemoTable    (       UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,       UserName varchar(100),       UserAge int,       UserAddress ... Read More

MySQL stored procedure parameters don't seem to work with special character @?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 06:58:36

273 Views

You cannot give MySQL stored procedure parameter with @ in the beginning. You can give @ sign in user-defined variables.Following is the syntax −SET @yourVariableName=yourValue;Let us implement the above syntax to correctly place @sign −mysql> DELIMITER // mysql> CREATE PROCEDURE declare_Variable(IN StudentName varchar(100))    BEGIN       SET @Name=StudentName; ... Read More

Is it possible to make an insert or an update in the same MySQL query?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 06:56:16

241 Views

Yes, use ON DUPLICATE KEY UPDATE. Let us first create a table −mysql> create table DemoTable(Id int NOT NULL PRIMARY KEY, Number int); Query OK, 0 rows affected (0.83 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1, 190) ON DUPLICATE KEY UPDATE Number=Number+10; Query ... Read More

Set the NULL values to 0 and display the entire column in a new column with MySQL SELECT

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 06:44:54

469 Views

For this, use IFNULL(). Let us first create a table −mysql> create table DemoTable (Value int); Query OK, 0 rows affected (1.02 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(NULL); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(10); Query OK, ... Read More

Set special characters for password while creating a new MySQL user?

AmitDiwan

AmitDiwan

Updated on 22-Aug-2019 06:40:42

506 Views

To set special characters for a password, use the following syntax −create user 'yourUserName'@'yourHostName' identified by 'yourSpecialCharacterPassword';Let us implement the above syntax in order to create a new user and set password with special characters −mysql> create user 'Mike'@'localhost' identified by 'Mike_123456'; Query OK, 0 rows affected (0.35 sec)Let us ... Read More

Execute MySQL query from the terminal without printing results?

AmitDiwan

AmitDiwan

Updated on 21-Aug-2019 12:15:23

637 Views

Let us first create a table −mysql> create table DemoTable709 (Amount int); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable709 values(100); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable709 values(560); Query OK, 1 row affected (0.15 ... Read More

Display records after a particular date in MySQL

AmitDiwan

AmitDiwan

Updated on 21-Aug-2019 12:12:22

2K+ Views

Let us first create a table −mysql> create table DemoTable708 (    CustomerName varchar(100),    ShippingDate date ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable708 values('John', '2019-01-21'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable708 ... Read More

MySQL query to order by NULL values

AmitDiwan

AmitDiwan

Updated on 21-Aug-2019 12:10:19

225 Views

Let us first create a table −mysql> create table DemoTable707 (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentFirstName varchar(100),    StudentMarks int ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable707(StudentFirstName, StudentMarks) values('John', 45); Query OK, ... Read More

MySQL query to get the current date records wherein one of the columns displays current date

AmitDiwan

AmitDiwan

Updated on 21-Aug-2019 12:07:06

259 Views

To achieve this, following is the syntax wherein we have used DATE(NOW()) −select *from yourTableName where DATE(yourColumnName)=DATE(NOW());Let us first create a table −mysql> create table DemoTable706 (    UserId varchar(100),    UserName varchar(100),    UserSignupDate datetime ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using ... Read More

MySQL query to retrieve current date from a list of dates

AmitDiwan

AmitDiwan

Updated on 21-Aug-2019 12:05:32

287 Views

Let’s say the current date is −2019-07-22Let us first create a table −mysql> create table DemoTable705 (ShippingDate datetime); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable705 values('2019-01-21 23:59:00'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable705 ... Read More

Advertisements