MySQLi Articles

Page 138 of 341

Text manipulation of strings containing “The ”? in MySQL

AmitDiwan
AmitDiwan
Updated on 17-Dec-2019 212 Views

You can use ORDER BY TRIM(). Let us first create a table −mysql> create table DemoTable    -> (    -> Title text    -> ); Query OK, 0 rows affected (1.09 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('MongoDB is a no SQL database'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('The MySQL is a relational database'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('The Java language is good'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable values('Python is good language'); Query ...

Read More

Fix Connectivity error in Java MySQL connection for connector to be set to class path?

AmitDiwan
AmitDiwan
Updated on 17-Dec-2019 435 Views

To fix, you need to put MySQL connector to the Java classpath. Import the jar file of the connector to the project folder for the IDE you are using.Here is the snapshot to place classpath −Let us now see the code for connectivity in Java with MySQL −This will produce the following output −

Read More

How to replace a character in a MySQL table?

AmitDiwan
AmitDiwan
Updated on 17-Dec-2019 406 Views

To replace only a single character, use REPLACE() in MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John Smitk'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('David Miller'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Adam Smitk'); 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 following ...

Read More

How to implement MySQL ORDER BY x where (x=col3 if col3!=null, else x=col2)?

AmitDiwan
AmitDiwan
Updated on 17-Dec-2019 137 Views

For this, you can use ORDER BY IFNULL(). Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(20),    -> CountryName varchar(20)    -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', NULL); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('David', 'AUS'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(NULL, 'UK'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(NULL, 'AUS'); Query OK, 1 row affected (0.10 sec) mysql> ...

Read More

What would happen if we insert empty values in a table with a column set as type TIMESTAMP CURRENT_TIMESTAMP?

AmitDiwan
AmitDiwan
Updated on 17-Dec-2019 338 Views

If we will insert nothing in the INSERT statement, then for timestamp type, it would insert the current date-time. Let us first create a table −mysql> create table DemoTable    -> (    -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> UserLoginDate timestamp default current_timestamp    -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.08 ...

Read More

Sort items in MySQL with dots?

AmitDiwan
AmitDiwan
Updated on 17-Dec-2019 180 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
AmitDiwan
Updated on 17-Dec-2019 271 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
AmitDiwan
Updated on 17-Dec-2019 158 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 display only 15 words from the left?

AmitDiwan
AmitDiwan
Updated on 17-Dec-2019 113 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
AmitDiwan
Updated on 17-Dec-2019 288 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
Showing 1371–1380 of 3,404 articles
« Prev 1 136 137 138 139 140 341 Next »
Advertisements