Found 4219 Articles for MySQLi

How to ORDER BY last 2 character string in MySQL?

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

2K+ Views

You can use ORDER BY RIGHT() to ORDER BY last 2 character string.The syntax is as followsselect yourColumnName from yourTableName ORDER BY RIGHT(yourColumnName , 2);To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table OrderByLast2CharactersDemo    -> (    -> CustomerId varchar(20),    -> CustomerName varchar(20)    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into OrderByLast2CharactersDemo(CustomerId, CustomerName) values('John-98', 'John'); Query OK, 1 row affected (0.20 sec) mysql> insert into OrderByLast2CharactersDemo(CustomerId, CustomerName) values('Carol-91', ... Read More

Verify that MySQL SET FOREIGN KEY CHECKS is set to = 1?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

662 Views

You can verify SET FOREIGN KEY CHECKS is set to = 1 or not with the help of variable@@foreign_key_checks;The syntax is as follows −select @@foreign_key_checks;You can use SHOW VARIABLES command. The syntax is as follows −show variables like 'foreign%';Now you can implement both the syntaxes.Case 1 − Using variable @@foreign_key_checks.The query is as follows −mysql> SELECT @@foreign_key_checks; Here is the output −+----------------------+ | @@foreign_key_checks | +----------------------+ | 1 | +----------------------+ 1 row in set (0.00 sec)Case 2 − Using SHOW commandThe ... Read More

Query with values prepended by ampersand works in Oracle but not in MySQL?

Samual Sam
Updated on 30-Jul-2019 22:30:25

96 Views

Ampersands work in Oracle. To work it in MySQL, use @ as shown in the following syntax −SET @yourVariableName1 = yourValue, @yourVariableName2 = yourValue, @yourVariableName3 =yourValue, .........N; insert into yourTableName values(@yourVariableName1, @yourVariableName2, @yourVariableName3, ........N);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table Student_Information    -> (    -> StudentId int,    -> StudentName varchar(100),    -> StudentAge int,    -> StudentMarks int,    -> StudentCountryName varchar(10)    -> ); Query OK, 0 rows affected (0.75 sec)Here is the query with values prepended by @. Insert some records ... Read More

Return null for date_format when input is null in MySQL?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

532 Views

Use IF() function to return null for date_format when input is null in MySQL. The syntax is as follows −SELECT IF(yourDateColumnName, date_format(yourDateColumnName, '%d/%m/%Y'), NULL) FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table returnNullWhenInputIsNullDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ShippingDate datetime    -> ); Query OK, 0 rows affected (1.21 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into returnNullWhenInputIsNullDemo(ShippingDate) values('2019-01-21'); Query OK, 1 row affected ... Read More

How to query MySQL on the current week?

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

2K+ Views

To query MySQL on the current week, you can use YEARWEEK() function.The syntax is as followsSELECT *FROM yourTableName WHERE YEARWEEK(yourDateColumnName) = YEARWEEK(NOW());To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table currentWeekDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(20), -> UserPostDate date -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into currentWeekDemo(UserName, ... Read More

Convert PHP variable “11:00 AM” to MySQL time format?

Samual Sam
Updated on 30-Jul-2019 22:30:25

249 Views

Use DateTime to convert PHP variable “11:00 AM: to MySQL time format.The PHP code is as follows −$phpTime = '11:00 AM'; echo('The PHP Time Format is ='); echo ($phpTime); $timeFormat = DateTime::createFromFormat( 'H:i A', $phpTime); $MySQLTimeFormat = $timeFormat->format( 'H:i:s'); echo (' '); echo('The MySQL Time Format is ='); echo ($MySQLTimeFormat);The snapshot of PHP code is as follows −Here is the output −The PHP Time Format is =11:00 AM The MySQL Time Format is =11:00:00

How to change MySQL error message language?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

158 Views

You can use lc_messages to change MySQL error message language. The syntax is as follows −SET lc_messages = 'yourLanguage';To understand the concept, let us create a table with some error and check the error message language.Here, we have set the local message to French. Let us first create a table −mysql> create table errorMessagelanguage    -> (    -> Error_MessageId int,    -> Error_Message varchar(100),    -> );The error message is as follows −ERROR 1064 (42000): Erreur de syntaxe près de ')' à la ligne 5Now you can set the error message to be in English language. The query is ... Read More

MySQL appears to DROP USER but user still exists in MySQL.users table?

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

114 Views

First check all the user and host from MySQL.user table with the help of select statement as shown belowmysql> select user, host from MySQL.user;The following is the output+------------------+-----------+ | user             | host      | +------------------+-----------+ | Bob              | %         | | Manish           | %         | | User2            | %         | | mysql.infoschema | %         | | mysql.session    | %   ... Read More

Best way to store weekly event in MySQL?

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

184 Views

Let us see the best way to store weekly events in MySQL. For that, first create a new table and include fields for every day as well.mysql> create table WeeklyEventDemo -> ( -> ID int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EventName varchar(20), -> Monday tinyint(1), -> Tuesday tinyint(1), -> Wednesday tinyint(1), -> Thursday tinyint(1), -> Friday tinyint(1), -> Saturday tinyint(1), -> Sunday tinyint(1), -> StartDate date, ... Read More

Can't find my.ini in MySQL directory?

Samual Sam
Updated on 30-Jul-2019 22:30:25

6K+ Views

The my.ini is in hidden folder of program data. First go to C: drive and then hidden folder of program data. From that, move to the MySQL version directory.Here is the snapshot of the C: drive −Click on C drive. The snapshot is as follows. Here, you can see the Program Data folder −Now go to MySQL under Program Data folder. The snapshot is as follows −Go to MySQL version. The snapshot is as follows −Note − Here, we are using MySQL version 8.0.12Here is the my.ini file.In order to reach the location, you can also use the following command ... Read More

Advertisements