
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

10K+ Views
To replace, use the REPLACE() MySQL function. Since you need to update the table for this, use the UPDATE() function with the SET clause.Following is the syntax −update yourTableName set yourColumnName=replace(yourColumnName, yourOldValue, yourNewValue);Let us first create a table −mysql> create table DemoTable ( FirstName varchar(100), CountryName varchar(100) ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', 'AUS'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Bob', 'AUS'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Chris', 'US'); Query OK, 1 ... Read More

180 Views
For this, you can use the ORDER BY CASE statement. Let us first create a table −mysql> create table DemoTable ( StudentName varchar(100), StudentMarks int ); Query OK, 0 rows affected (0.97 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 45); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('John', 67); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('David', 89); Query OK, 1 row affected (0.46 sec) mysql> insert into DemoTable values('John', 98); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Mike', ... Read More

246 Views
To order by the first number in a set of numbers, use ORDER BY SUBSTRING_INDEX(). Let us first create a table −mysql> create table DemoTable ( SetOfNumbers text ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('245, 654, 76, 89, 98'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2000, 567, 9090, 6789'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('1001, 90595, 657, 99'); Query OK, 1 row affected (0.20 sec)Display all records from the table using select statement −mysql> ... Read More

688 Views
Yes, but you need to add a backtick symbol to the reserved word (index) to avoid error while using it as a column name.Let us first create a table −mysql> create table DemoTable ( `index` int ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1000); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(1020); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(967); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(567); Query OK, 1 row affected (0.12 ... Read More

103 Views
Let us first create a table −mysql> create table DemoTable ( FirstName varchar(100), Score int ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('David', 59); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Chris', 97); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values('Bob', 98); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Carol', 91); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the ... Read More

88 Views
For this, use IF() along with IS NULL property. Let us first create a table −mysql> create table DemoTable ( Name varchar(100), CountryName varchar(100) ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 'US'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Mike', NULL); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Name) values('David'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable values('Bob', 'AUS'); Query OK, 1 row affected (0.45 sec)Display all records from the table using select ... Read More

403 Views
Let us first create a table −mysql> create table DemoTable ( UserId int, UserName varchar(100) ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(101, 'Bob'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(102, 'David'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(103, 'Mike'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(104, 'Sam'); Query OK, 1 row affected (0.16 sec)Display all records ... Read More

209 Views
Let us first create a table −mysql> create table DemoTable ( StudentId int, StudentFirstName varchar(100) ); Query OK, 0 rows affected (0.88 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'John'); Query OK, 1 row affected (0.32 sec) mysql> insert into DemoTable values(101, 'Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(102, 'John'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(103, 'Sam'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(104, 'Sam'); Query OK, 1 row affected (0.13 sec)Display all records ... Read More

26K+ Views
You can easily insert DateTime with the MySQL command line. Following is the syntax − insert into yourTableName values(‘yourDateTimeValue’); Let us first create a table − mysql> create table DemoTable ( DateOfBirth datetime ); Query OK, 0 rows affected (0.97 sec) Insert some records in the table using insert command − mysql> insert into DemoTable values('1998-01-23 12:45:56'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values('2010-12-31 01:15:00'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('2015-04-03 14:00:45'); Query OK, 1 row affected (0.10 sec) Display all records from the table using select statement ... Read More

367 Views
Let us first create a table. Following is the query to create a table in database ‘web’ −mysql> create table DemoTable ( AdmissionDate date ); Query OK, 0 rows affected (0.53 sec)Here is the Java code to insert empty(NULL) java.sql.Date in MySQL DB −import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; public class InsertNullDateDemo{ public static void main(String[] args){ Connection con=null; PreparedStatement ps=null; try{ con=DriverManager.getConnection("jdbc:mysql://localhost:3306/web?useSSL=false", "root", "123456"); String query="insert into DemoTable(AdmissionDate) values(?) "; ps= con.prepareStatement(query); ... Read More