
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4218 Articles for MySQLi

145 Views
You can use str_to_date() for this conversion. Let us first create a table −mysql> create table DemoTable ( stringDate varchar(100) ); Query OK, 0 rows affected (0.86 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('1h 15 min'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values('2h 30 min'); Query OK, 1 row affected (0.21 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+------------+ | stringDate | +------------+ | 1h 15 min | | 2h 30 min | +------------+ 2 rows in set ... Read More

203 Views
No, you need to use open and close parenthesis like this ( ) while creating a table. Use the below syntax −CREATE TABLE IF NOT EXISTS yourTableName ( yourColumnName1 dataType1, . . . . . N );Let us first create a table −mysql> CREATE TABLE IF NOT EXISTS DemoTable ( CustomerId int, CustomerName varchar(20), CustomerAge int , PRIMARY KEY(CustomerId) ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1, 'Chris', 25); Query OK, 1 row ... Read More

243 Views
Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Subject varchar(20), Price int ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Subject, Price) values('MySQL', 456); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(Subject, Price) values('MySQL', 456); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Subject, Price) values('MongoDB', 56); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(Subject, Price) values('MongoDB', 60); Query OK, 1 row affected (0.13 sec) mysql> ... Read More

564 Views
For this, use the LIKE operator. Let us first create a table:mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Password varchar(100) ); Query OK, 0 rows affected (1.27 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Password) values('John@--123'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(Password) values('---Carol234'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Password) values('--David987'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Password) values('Mike----53443'); Query OK, 1 row affected (0.30 sec)Display all records from the table using select ... Read More

333 Views
For year and month date fetching, you can use YEAR() and MONTH() function in MySQL. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ShippingDate datetime ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ShippingDate) values('2019-01-31'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(ShippingDate) values('2018-12-01'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(ShippingDate) values('2019-06-02'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable(ShippingDate) values('2019-11-18'); Query OK, 1 row ... Read More

426 Views
For this, you can use multiple OR. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(10), LastName varchar(10), Age int, CountryName varchar(10) ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstName, LastName, Age, CountryName) values('John', 'Smith', 21, 'US'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(FirstName, LastName, Age, CountryName) values('Carol', 'Taylor', 22, 'AUS'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(FirstName, LastName, Age, CountryName) values('David', ... Read More

1K+ Views
For this, use the aggregate function COUNT() along with GROUP BY. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value int ); Query OK, 0 rows affected (0.74 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value) values(976); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Value) values(67); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Value) values(67); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Value) values(1); Query OK, 1 row affected (0.27 sec) mysql> ... Read More

409 Views
The query SELECT NOW() gives the current date as well as current time. If you want only current date, use only CURDATE(). Following is the syntax for datetime −SELECT NOW();The syntax for only date.SELECT CURDATE();Let us now implement the above syntax −Case 1 : If you want both current date and time −mysql> SELECT NOW();Output+-----------------------+ | NOW() | +-----------------------+ | 2019-06-02 15 :30 :39 | +-----------------------+ 1 row in set (0.00 sec)Case 2 : If you want the current date only −mysql> SELECT CURDATE();Output+------------+ | CURDATE() | +------------+ | 2019-06-02 | +------------+ 1 row in set (0.00 sec)

789 Views
To add two weeks to a date in MySQL, use DATE_ADD() −insert into yourTableName(yourColumnName) values(date_add(now(), interval 2 week));Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ShippingDate datetime ); Query OK, 0 rows affected (0.62 sec)Following is the query to get the current date −mysql> select now(); +-----------------------+ | now() | +-----------------------+ | 2019-06-02 10 :36 :49 | +-----------------------+ 1 row in set (0.00 sec)Insert some records in the table using ... Read More

544 Views
Let us first create a table with one of the column as ID −mysql> create table DemoTable ( ID int, StudentName varchar(10), CountryName varchar(20) ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(0, 'David', 'AUS'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(3, 'Chris', 'UK'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values(8, 'Carol', 'US'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values(9, 'Sam', 'US'); Query OK, 1 row affected (0.14 ... Read More