Found 4219 Articles for MySQLi

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

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

363 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 check the table where MySQL user and host is stored −mysql> select user, host from MySQL.user;This will produce the following output. The new user created successfully −+------------------+-----------+ | user             | host      | +------------------+-----------+ | Bob              | ... Read More

Can we remove a primary key from MySQL table?

AmitDiwan
Updated on 22-Aug-2019 06:31:37

367 Views

Yes, we can remove a primary key using the DROP in MySQL. Following is the syntax −alter table yourTableName drop primary key;Let us first create a table −mysql> create table DemoTable    (       UserId int NOT NULL PRIMARY KEY    ); Query OK, 0 rows affected (0.58 sec)Following is the query to check the description of table −mysql> desc DemoTable;This will produce the following output displaying the Primary Key −+--------+---------+------+-----+---------+-------+ | Field  | Type | Null | Key | Default | Extra | +--------+---------+------+-----+---------+-------+ | UserId | int(11) | NO | PRI ... Read More

How to get max(id) of row data in MySQL?

AmitDiwan
Updated on 21-Aug-2019 12:16:55

6K+ Views

To get max(id), use MAX() method in MySQL. Following is the syntax −select MAX(yourColumnName) AS anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable710 (Id int); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable710 values(1001); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable710 values(2001); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable710 values(1998); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable710 values(1789); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable710 values(1678); Query OK, 1 ... Read More

Execute MySQL query from the terminal without printing results?

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

435 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 sec) mysql> insert into DemoTable709 values(7800); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable709 values(1020); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select *from DemoTable709;This will produce the following output -+--------+ | Amount | +--------+ | 100 ... Read More

Display records after a particular date in MySQL

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

1K+ 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 values('Chris', '2019-03-24'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable708 values('Robert', '2019-04-26'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable708 values('David', '2019-07-22'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from DemoTable708;This will produce the ... Read More

MySQL query to order by NULL values

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

142 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, 1 row affected (0.16 sec) mysql> insert into DemoTable707(StudentFirstName, StudentMarks) values(NULL, 65); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable707(StudentFirstName, StudentMarks) values('Chris', 78); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable707(StudentFirstName, StudentMarks) values(NULL, 89); Query OK, 1 row affected (0.19 sec) mysql> insert into ... Read More

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

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

172 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 insert command −mysql> insert into DemoTable706 values('John1@gmail.com', 'John', '2019-01-31 12:45:22'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable706 values('Chris123@gmail.com', 'Chris', '2019-07-22 10:05:02'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable706 values('12Robert@gmail.com', 'Robert', '2019-06-22 11:25:22'); Query OK, 1 row affected (0.22 sec) mysql> insert into ... Read More

MySQL query to retrieve current date from a list of dates

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

204 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 values('2019-07-22 00:00:30'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable705 values('2019-07-21 12:01:30'); Query OK, 1 row affected (0.44 sec)Display all records from the table using select statement −mysql> select *from DemoTable705;This will produce the following output -+---------------------+ | ShippingDate | ... Read More

Get count of how many times a string appears in a MySQL column?

AmitDiwan
Updated on 21-Aug-2019 12:04:15

284 Views

Let us first create a table −mysql> create table DemoTable704 (SubjectName text); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable704 values('Introduction to MySQL'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable704 values('Introduction to MongoDB'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable704 values('Introduction to MySQL'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable704 values('Introduction to Java'); Query OK, 1 row affected (0.39 sec) mysql> insert into DemoTable704 values('Introduction to MongoDB'); Query OK, 1 row affected (0.14 sec) mysql> insert into ... Read More

Return 0 in a new column when record is NULL in MySQL?

AmitDiwan
Updated on 21-Aug-2019 12:03:03

172 Views

For this, you can use CASE statement. Let us first create a table −mysql> create table DemoTable703 (Price int); Query OK, 0 rows affected (0.46 sec)Insert some records in the table using insert command −mysql> insert into DemoTable703 values(102); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable703 values(null); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable703 values(0); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable703 values(500); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable703 values(100); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable703 values(null); Query ... Read More

Advertisements