Found 4219 Articles for MySQLi

Select text after last slash in MySQL?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

870 Views

You need to use substring_index() function from MySQL to select text.The syntax is as followsSELECT substring_index(yourColumnName, '/', -1) AS anyAliasName FROM yourTableName;To understand the above concept, let us create a table. The query to create a table is as followsmysql> create table selectTextAfterLastSlashDemo - > ( - > UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > UserPathDirectory varchar(200) - > ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into selectTextAfterLastSlashDemo(UserPathDirectory) values('C:/MyFolder1/MyEntityFramework'); Query OK, 1 ... Read More

Best way to change the date format in MySQL SELECT?

George John
Updated on 30-Jul-2019 22:30:25

1K+ Views

The best way to change the date format in MySQL SELECT is as followsSELECT DATE_FORMAT(yourColumnName, "%d/%m/%Y %H:%i") AS anyAliasName FROM yourTableName WHERE yourCondition;To understand the above concept, let us create a table. The query to create a table is as followsmysql> create table bestDateFormatDemo - > ( - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > ArrivalDateTime datetime - > ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into bestDateFormatDemo(ArrivalDateTime) values(now()); Query OK, ... Read More

Does MySQL have an expanded output flag similar PostgreSQL?

Chandu yadav
Updated on 30-Jul-2019 22:30:25

83 Views

Yes, you can get expanded out in MySQL using the /G, instead of semicolon(;). The syntax is as followsSELECT *FROM yourTableName\GLet us first create a table as an examplemysql> create table expandedOutputDemo    - > (    - > EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    - > EmployeeName varchar(20),    - > EmployeeAge int    - > ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into expandedOutputDemo(EmployeeName, EmployeeAge) values('Larry', 27); Query OK, 1 row affected (0.16 sec) mysql> insert into expandedOutputDemo(EmployeeName, EmployeeAge) values('Mike', 29); Query ... Read More

How can I the date of creation and updation of tables in MySQL?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

147 Views

Get the create and update tables exact date using the create_time or update_time in MySQL.At first, use the SHOW command. The syntax is as followsSHOW TABLE STATUS;We are considering our database ‘test3’, which is already having some tablesmysql> use test3; Database changedNow use the following query to display all the tables in the database test3mysql> show tables;The following is the output+-------------------------+ | Tables_in_test3         | +-------------------------+ | add6hour                | | deletedemo              | | differentdatetime       | | fieldlessthan5chars     | | ... Read More

Rename Root @ localhost username in MySQL?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

504 Views

The syntax is as follows to rename Root @localhostUPDATE MySQL.user SET user = ‘yourNewRootName’ WHERE user = 'root';To understand the above concept, let us check all the user names and host. The query is as followsmysql> select user, host from MySQL.user;The following is the output+------------------+-----------+ | user             | host      | +------------------+-----------+ | Bob              | %         | | Manish           | %         | | User2            | %       ... Read More

Which version is my MySQL?

George John
Updated on 30-Jul-2019 22:30:25

106 Views

You can use two approaches to know the version of MySQL. In the first approach, you can use version() to know the MySQL Server version. The first approach is as followsSELECT VERSION();In the second approach, you can use SHOW VARIABLES command to know the MySQL version. The second approach is as followsSHOW VARIABLES WHERE Variable_name = 'version';Let us learn about both the syntaxes one by one.Using version()mysql> select version();The following is te output displaying the current version of the MySQL you are using+-----------+ | version() | +-----------+ | 8.0.12 | +-----------+ 1 row in set (0.00 sec)The ... Read More

How to find the previous and next record using a single query in MySQL?

Chandu yadav
Updated on 30-Jul-2019 22:30:25

6K+ Views

You can use UNION to get the previous and next record in MySQL.The syntax is as follows(select *from yourTableName WHERE yourIdColumnName > yourValue ORDER BY yourIdColumnName ASC LIMIT 1) UNION (select *from yourTableName WHERE yourIdColumnName < yourValue ORDER BY yourIdColumnName DESC LIMIT 1);To understand the concept, let us create a table. The query to create a table is as followsmysql> create table previousAndNextRecordDemo - > ( - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > Name varchar(30) - > ); Query OK, 0 rows affected (1.04 ... Read More

Is it possible to calculate a correlation in a MySQL query?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

1K+ Views

Yes, it is possible to calculate a correlation in a query. To understand the correlation in a query, you need to first create a table. The query to create a table is as followsmysql> create table correlationDemo - > ( - > value float not null, - > value2 float not null - > ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table with the help of insert command. The query is as follows to insert records in the tablemysql> insert into correlationDemo values(1, ... Read More

How to select ID column as null in MySQL?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

434 Views

Let us first create a table. The query to create a table is as followsmysql> create table selectAllDemo - > ( - > Name varchar(100), - > Age int - > ); Query OK, 0 rows affected (1.90 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into selectAllDemo values('John', 25); Query OK, 1 row affected (0.99 sec) mysql> insert into selectAllDemo values('Carol', 26); Query OK, 1 row affected (0.42 sec) mysql> insert into selectAllDemo values('Bob', 30); Query OK, 1 row affected (1.57 ... Read More

Count two different columns in a single query in MySQL?

George John
Updated on 30-Jul-2019 22:30:25

5K+ Views

You can use CASE statement to count two different columns in a single query. To understand the concept, let us first create a table. The query to create a table is as follows.mysql> create table CountDifferentDemo    - > (    - > ProductId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    - > ProductName varchar(20),    - > ProductColor varchar(20),    - > ProductDescription varchar(20)    - > ); Query OK, 0 rows affected (1.06 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into CountDifferentDemo(ProductName, ProductColor, ProductDescription) values('Product-1', 'Red', 'Used'); Query OK, 1 row ... Read More

Advertisements