- 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
398 Views
Let us first create a table −mysql> create table DemoTable ( CustomerName varchar(100), CustomerCountryName varchar(100) ); Query OK, 0 rows affected (0.95 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 'US'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Bob', 'UK'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Carol', NULL); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('David', 'AUS'); Query OK, 1 row affected (0.32 sec) mysql> insert into DemoTable values('Mike', NULL); Query OK, 1 row affected (0.18 sec)Display all records ... Read More
213 Views
You can use concat(). Let us first create a table −mysql> create table DemoTable ( Value int ); Query OK, 0 rows affected (0.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(200); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(200); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(200); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(100); Query ... Read More
184 Views
For this, you can use LENGTH() along with REPLACE(). Let us first create a table −mysql> create table DemoTable ( Value int ); Query OK, 0 rows affected (1.22 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10002000); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(00000); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(400560); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+----------+ | Value | +----------+ | 10002000 ... Read More
199 Views
For this, you can use IFNULL(). Let us first create a table −mysql> create table DemoTable ( FirstName varchar(100), LastName varchar(100) ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', 'Doe'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values(NULL, 'Taylor'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('David', NULL); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(NULL, 'Miller'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> ... Read More
112 Views
For this, you can use IFNULL(). Let us first create a table −mysql> create table DemoTable ( Value1 int, Value2 int ); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, NULL); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(20, 40); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values(3, NULL); Query OK, 1 row affected (0.20 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+--------+--------+ | Value1 | Value2 ... Read More
194 Views
Following is the declaration for a UNIQUE clause in MySQL −create table yourTableName ( yourColumnName1 dataType, yourColumnName2 dataType, UNIQUE(yourColumnName1), UNIQUE(yourColumnName1) );Let us first create a table −mysql> create table DemoTable ( Value int, Value2 int, UNIQUE(Value), UNIQUE(Value2) ); Query OK, 0 rows affected (13.98 sec)Insert some records in the table using insert command. Here, duplicate records won’t insert because we have used UNIQUE above −mysql> insert into DemoTable values(10, 20) ; Query OK, 1 row affected (0.32 sec) mysql> insert into DemoTable values(10, 30); ERROR 1062 (23000): Duplicate entry '10' for key ... Read More
416 Views
Let us first create a table −mysql> create table DemoTable ( AdmissionDate datetime ); Query OK, 0 rows affected (8.99 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2010-01-10 12:30:45'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2010-01-10 12:30:45'); Query OK, 1 row affected (0.46 sec) mysql> insert into DemoTable values('2010-01-10 12:30:45'); Query OK, 1 row affected (0.71 sec) mysql> insert into DemoTable values('2010-01-12 12:30:45'); Query OK, 1 row affected (1.22 sec) mysql> insert into DemoTable values('2010-01-20 12:30:45'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2010-01-20 ... Read More
158 Views
Let’s say we have a database “web” and we need to get all the tables having a specific column ’StudentFirstName’.For this, below is the query −mysql> select myColumnName.table_name from information_schema.columns myColumnName where myColumnName.column_name = 'StudentFirstName' and table_schema='web';This will produce the following output −+---------------+ | TABLE_NAME | +---------------+ | demotable109 | | demotable297 | | demotable335 | | demotable395 | | demotable418 | | demotable425 | | demotable436 | +---------------+ 7 rows in set (0.14 sec)Therefore, the above tables have one of the column names as “StudentFirstName”.Let us check the description ... Read More
1K+ Views
To convert MySQL timestamp to UNIX Timestamp, use the UNIX_TIMESTAMP(). Following is the syntax −select unix_timestamp(yourColumnName) from yourTableName;Let us first create a table −mysql> create table DemoTable( Duetimestamp timestamp ); Query OK, 0 rows affected (2.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(now()); Query OK, 1 row affected (1.53 sec) mysql> insert into DemoTable values('2016-01-21 12:34:00'); Query OK, 1 row affected (0.73 sec) mysql> insert into DemoTable values('2018-05-01 02:00:00'); Query OK, 1 row affected (0.42 sec) mysql> insert into DemoTable values('2017-03-02 01:10:20'); Query OK, 1 row affected (10.19 sec)Display all records from ... Read More
594 Views
To replace & with an ampersand, use MySQL REPLACE(). Let us first create a table −mysql> create table DemoTable( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value varchar(100) ); Query OK, 0 rows affected (1.06 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value) values('@amp'); Query OK, 1 row affected (0.33 sec) mysql> insert into DemoTable(Value) values('&'); Query OK, 1 row affected (1.09 sec) mysql> insert into DemoTable(Value) values('#amp'); Query OK, 1 row affected (0.28 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+----+-------+ ... Read More