Found 4219 Articles for MySQLi

Sort items in MySQL with dots?

AmitDiwan
Updated on 17-Dec-2019 06:56:06

108 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Value varchar(20)    -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('20'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('10.5'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('11'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('10'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('20.5'); Query OK, 1 row affected (0.13 sec)Display all records from the table ... Read More

The easiest way to insert date records in MySQL?

AmitDiwan
Updated on 17-Dec-2019 06:37:37

188 Views

Use the STR_TO_DATE() method to insert date records as in the below syntax −select str_to_date(yourColumnName, '%b %Y') from yourTableName;Let us first create a table −mysql> create table DemoTable    -> (    -> JoiningYear varchar(20)    -> ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Jan 2018'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('May 2107'); Query OK, 1 row affected (0.32 sec) mysql> insert into DemoTable values('Aug 2019'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Oct 2020'); Query OK, ... Read More

Implement MySQL REGEXP to fetch records with . and numbers

AmitDiwan
Updated on 17-Dec-2019 06:33:48

76 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Version varchar(20)    -> ); Query OK, 0 rows affected (0.77 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('1.0.0'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('2.s6.9'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('1.5.0'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+---------+ | Version | +---------+ | 1.0.0   | | 2.s6.9  | ... Read More

MySQL Query to set currency records

AmitDiwan
Updated on 17-Dec-2019 06:31:26

190 Views

Use FORMAT() in MySQL to display currency records and display them in the correct form. Let us first create a table −mysql> create table DemoTable    -> (    -> Amount DECIMAL(15, 4)    -> ); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(90948484); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(1000000000); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(1535353536); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(773646463); Query OK, 1 row affected (0.20 sec)Display all ... Read More

MySQL query to display only 15 words from the left?

AmitDiwan
Updated on 17-Dec-2019 06:29:59

54 Views

For this, use LEFT in MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> Title text    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Java database connectivity to MySQL database'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Python with django framework'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('C with data structure and algorithm'); Query OK, 1 row affected (0.33 sec)Display all records from the table using select statement −mysql> select ... Read More

Replacing numbers on a comma delimited result with MySQL?

AmitDiwan
Updated on 17-Dec-2019 06:27:59

138 Views

For this, use CASE statement along with FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable1629     -> (     -> Month varchar(100)     -> ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command.mysql> insert into DemoTable1629 values('2, 4, 6'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1629 values('1, 3, 5, 12'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1629 values('7, 8, 9, 10'); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement − mysql> select ... Read More

Select total from a MySQL table based on month

AmitDiwan
Updated on 28-Feb-2020 05:26:08

158 Views

For this, you can use GROUP BY MONTH(). Let us first create a table −mysql> create table DemoTable1628     -> (     -> PurchaseDate date,     -> Amount int     -> ); Query OK, 0 rows affected (1.55 sec)Insert some records in the table using insert command.mysql> insert into DemoTable1628 values('2019-01-10', 1500); Query OK, 1 row affected (0.68 sec) mysql> insert into DemoTable1628 values('2019-10-10', 2000); Query OK, 1 row affected (0.61 sec) mysql> insert into DemoTable1628 values('2019-10-24', 100); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1628 values('2019-11-10', 500); Query OK, 1 row affected ... Read More

Create MySQL datetime column with default 0000-00-00?

AmitDiwan
Updated on 17-Dec-2019 06:27:12

697 Views

To set default, you can use the DEFAULT keyword in MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeName varchar(20),    -> EmployeeJoiningDate datetime default '0000-00-00 00:00:00'    -> )ENGINE=MyISAM, AUTO_INCREMENT=100; Query OK, 0 rows affected (0.21 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(EmployeeName) values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(EmployeeName) values('David'); Query OK, 1 row affected (0.04 sec) mysql> insert into DemoTable(EmployeeName) values('Mike'); Query OK, 1 row affected (0.03 sec) mysql> ... Read More

Java – MySQL connection with ipAddress

AmitDiwan
Updated on 17-Dec-2019 06:24:11

647 Views

Set the JDBC MySQL URL in the DriverManager.getConnection to connect with IP Address. Following is the code to connect using IP Address −Exampleimport java.sql.Connection; import java.sql.DriverManager; public class JavaIP {    public static void main(String[] args) {       String hostURL = "jdbc:mysql://192.168.43.144:3306/web?useSSL=false";       Connection con = null;       try {          con = DriverManager.getConnection(hostURL, "root", "123456");          System.out.println("connection successful via ip address");       }       catch (Exception e) {          e.printStackTrace();       }    } }OutputThis will produce the following output −connection successful via ip addressHere is the snapshot of the output −

How to get the count of both present and absent students for a year in MySQL?

AmitDiwan
Updated on 28-Feb-2020 05:31:07

966 Views

For this, you can use IF() along with aggregate function SUM(). Let us first create a table −mysql> create table DemoTable1617     -> (     -> Attendance varchar(20),     -> CurrentYear int     -> ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1617 values('Present', 2019); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1617 values('Absent', 2019); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1617 values('Absent', 2017); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1617 values('Present', 2019); Query ... Read More

Advertisements