Found 4219 Articles for MySQLi

How to escape parentheses in MySQL REGEXP clause and display only specific values with parentheses?

AmitDiwan
Updated on 30-Dec-2019 06:26:07

661 Views

Let us first create a table −mysql> create table DemoTable1908    (    Code text    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1908 values('MySQL(1)Database'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1908 values('MongoDB 2 Database'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1908 values('MySQL(3)Database'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1908 values('SQL Server(10)Database'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1908 values('MySQL 8 Database'); Query OK, 1 row affected (0.00 sec)Display all records from ... Read More

Create table query with manual AUTO_INCREMENT start value in MySQL?

AmitDiwan
Updated on 30-Dec-2019 06:24:21

118 Views

Let us first create a table −mysql> create table DemoTable1907    (    UserId int NOT NULL AUTO_INCREMENT,    UserName varchar(20),    UserAge int,    UserCountryName varchar(20),    PRIMARY KEY(UserId)    )ENGINE=MyISAM, AUTO_INCREMENT=100; Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1907(UserName, UserAge, UserCountryName) values('Chris', 26, 'US'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1907(UserName, UserAge, UserCountryName) values('David', 38, 'UK'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1907(UserName, UserAge, UserCountryName) values('John', 28, 'AUS'); Query OK, 1 row affected (0.00 sec)Display all records from the ... Read More

How to change format of dates in a table column with a MySQL query?

AmitDiwan
Updated on 30-Dec-2019 06:22:02

409 Views

To change format of dates, use the DATE_FORMAT() function. Let us first create a table −mysql> create table DemoTable1906    (    DueTime datetime    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1906 values(now()); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1906 values(curdate()); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1906 values('2017-10-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1906 values('2015-01-12'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1906 values('2018-04-25'); Query OK, 1 row affected (0.00 ... Read More

MySQL Count Distinct values process is very slow. How to fasten it?

AmitDiwan
Updated on 30-Dec-2019 06:20:28

271 Views

To fasten the process, you can use INDEX. Let us first create a table −mysql> create table DemoTable1905    (    FirstName varchar(20),    LastName varchar(20) ,    INDEX F_L_Name(FirstName, LastName)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1905 values('John', 'Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1905 values('John', 'Doe'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1905 values('Adam', 'Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1905 values('John', 'Doe'); Query OK, 1 row affected (0.00 sec) ... Read More

How to escape backslashes in MySQL with JDBC?

AmitDiwan
Updated on 30-Dec-2019 06:17:55

308 Views

To escape backslashes, use PreparedStatement while inserting records. Let us first create a table −mysql> create table DemoTable1904    (    ClientId int,    ClientName varchar(20),    ClientAge int    ); Query OK, 0 rows affected (0.00 sec)The Java code is as follows −import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; public class EscapeBackslashesDemo {    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 DemoTable1904(ClientId, ... Read More

MySQL UPDATE column names and set None values with N/A?

AmitDiwan
Updated on 30-Dec-2019 06:14:54

201 Views

Let us first create a table −mysql> create table DemoTable1903    (    FirstName varchar(20),    LastName varchar(20) ,    Age int    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1903 values('John', 'Smith', 23); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1903 values('None', 'Miller', 28); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1903 values('None', 'Taylor', 26); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1903 values('Chris', 'Brown', 26); Query OK, 1 row affected (0.00 sec)Display all records from the table ... Read More

How to search for particular strings between comma separated values in MySQL?

AmitDiwan
Updated on 27-Dec-2019 07:11:07

517 Views

For this, use REGEXP. Let us first create a table −mysql> create table DemoTable1902    (    Subjects text    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1902 values('MongoDB, Java, Python'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1902 values('SQL Server, MySQL, PL/SQL'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1902 values('Hibernate, Spring, JPA'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1902;This will produce the following output −+-------------------------+ | Subjects ... Read More

MySQL query to copy records from one table to another with different columns

AmitDiwan
Updated on 27-Dec-2019 07:09:41

519 Views

For this you can use INSERT INTO SELECT statement. Let us first create a table −mysql> create table DemoTable1900    (    ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ClientName varchar(20),    ClientAge int default 29    ) auto_increment=1000; Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1900(ClientName, ClientAge) values('Chris', 45); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1900(ClientName, ClientAge) values('David', 29); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1900(ClientName, ClientAge) values('Mike', 37); Query OK, 1 row affected (0.00 sec) mysql> insert into ... Read More

How to replace a particular character in a MySQL column?

AmitDiwan
Updated on 27-Dec-2019 07:06:24

293 Views

To replace a particular character, use REPLACE() and to update, use the UPDATE command. Let us first create a table −mysql> create table DemoTable1899    (    Code varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1899 values('John_123'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1899 values('32189_Sam_987'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1899 values('Miller_David_456_909'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1899;This will produce the following output ... Read More

MySQL ORDER BY with numeric user-defined variable?

AmitDiwan
Updated on 27-Dec-2019 07:05:19

267 Views

Let us first create a table −mysql> create table DemoTable1898    (    Number int    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1898 values(10); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1898 values(70); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1898 values(30); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1898 values(50); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1898 values(40); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement ... Read More

Advertisements