- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 4219 Articles for MySQLi
911 Views
To create a table name like year (2019), use PREPARE statement. Let us first create a table −mysql> create table DemoTable1959 ( UserName varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1959 values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1959 values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1959 values('Bob'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1959;This will produce the following output −+----------+ | UserName ... Read More
607 Views
For this, use ZEROFILL and alter the table to begin from the same sequence −alter table yourTableName change yourColumnName yourColumnName int(3) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY;To understand the above syntax, let us first create a table −mysql> create table DemoTable1958 ( UserId int, UserName varchar(20) ); Query OK, 0 rows affected (0.00 sec)Here is the query to alter generated sequence number to begin from 001:mysql> alter table DemoTable1958 change UserId UserId int(3) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY; Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0Let ... Read More
298 Views
Let us first create a table −mysql> create table DemoTable1957 ( EmployeeId int, EmployeeName varchar(20), EmployeeSalary int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1957 values(1, 'Chris', 240000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1957 values(2, 'Bob', 120000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1957 values(3, 'David', 180000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1957 values(4, 'Mike', 650000); Query OK, 1 row affected (0.00 sec)Display all records from the table using ... Read More
Select a column if condition is met in MySQL to fetch records from current date and current date + 1
432 Views
Let us first get the current date −mysql> select curdate();This will produce the following output −+------------+ | curdate() | +------------+ | 2019-12-15 | +------------+ 1 row in set (0.00 sec)Let us first create a table −mysql> create table DemoTable1956 ( ProductId int, ProductName varchar(20), CustomerName varchar(20), ShippingDate date ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1956 values(101, 'Product-1', 'Sam', '2019-10-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1956 values(102, 'Product-2', 'Carol', '2018-12-01'); Query OK, 1 row affected (0.00 sec) ... Read More
494 Views
Let us first create a table −mysql> create table DemoTable1955 ( UserId int NOT NULL AUTO_INCREMENT , PRIMARY KEY(UserId) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1955 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1955 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1955 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1955 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1955 values(); Query OK, 1 row affected (0.00 sec)Display ... Read More
79 Views
To fetch day name, use DAYNAME() function in MySQL. Let us first create a table −mysql> create table DemoTable1954 ( ShippingDate date ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1954 values('2019-12-15'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1954 values('2018-04-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1954 values('2019-01-31'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1954 values('2016-10-01'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * ... Read More
475 Views
Let us first create a table −mysql> create table DemoTable1953 ( StudentName varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1953 values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1953 values(NULL); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1953 values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1953 values(NULL); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1953;This will produce the following output −+-------------+ | ... Read More
88 Views
For this, use CASE statement. Let us first create a table −mysql> create table DemoTable1952 ( Marks int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1952 values(35); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1952 values(65); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1952 values(55); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1952 values(39); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1952;This will produce ... Read More
617 Views
To split float value in two columns, the first column will have a value before decimal. The second column will have a value after decimal. For this, you can use SUBSTRING_INDEX() along with CAST(). Let us first create a table −mysql> create table DemoTable1951 ( Value1 varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1951 values('100.50'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1951 values('70.90'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1951 values('1000.55'); Query OK, 1 row affected ... Read More
2K+ Views
Let us create a table −mysql> create table DemoTable1950 ( Amount float ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1950 values(45.60); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1950 values(101.78); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1950 values(75.90); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1950 values(89.45); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1950;This will produce the following output −+--------+ | Amount ... Read More