- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4219 Articles for MySQLi
2K+ Views
The word order is a reserved order in MySQL and you have used it in the query. To get rid of the syntax error, you need to use backticks(` `) around the order.The correct syntax is as follows −select *from yourTableName ORDER BY `order` DESC;Let us first create a table −mysql> create table DemoTable ( `order` int ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(89); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(67); Query OK, 1 row affected (0.13 sec) ... Read More
93 Views
For this, use both GROUP BY and ORDER BY clause. Let us first create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentGrade char(1) ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentGrade) values('A'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentGrade) values('F'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(StudentGrade) values('C'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable(StudentGrade) values('A'); Query OK, 1 row affected (0.23 sec) mysql> insert ... Read More
497 Views
For this, you can use COLLATE. Following is the syntax −select *from yourTableName where yourColumnName LIKE yourValue COLLATE utf8_bin;Let us first create a table −mysql> create table DemoTable ( LastName varchar(100) ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Brown'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('BROWN'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values('brown'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('BRoWN'); Query OK, 1 row affected (0.14 sec)Display all records ... Read More
497 Views
Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Score int ); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Score) values(67); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Score) values(78); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Score) values(90); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Score) values(56); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+----+-------+ ... Read More
1K+ Views
To remove last char if it is a specific character then use SUBSTRING(). Let us first create a table −mysql> create table DemoTable ( SubjectName varchar(100) ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('MySQL'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('MongoDB?'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Java?'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('C'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select ... Read More
592 Views
You can use DATE_ADD() function with where clause for this. Let us first create a table −mysql> create table DemoTable ( ShippingDate date ); Query OK, 0 rows affected (0.54 sec)Note : The current date and time is as follows, we found using NOW() −mysql> select now(); +-----------------------+ | now() | +-----------------------+ | 2019-06-04 20 :43 :57 | +-----------------------+ 1 row in set (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-06-16'); Query OK, 1 ... Read More
109 Views
Use BETWEEN clause to search between columns. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Score1 int, Score2 int ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Score1, Score2) values(45, 65); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable(Score1, Score2) values(450, 680); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Score1, Score2) values(800, 900); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement ... Read More
502 Views
To concatenate two tables, UNION ALL in MySQL. Let us create a table −mysql> create table DemoTable1 ( Id int, FirstName varchar(20) ); Query OK, 0 rows affected (1.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(10, 'John'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable1 values(20, 'Carol'); Query OK, 1 row affected (0.28 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;Output+------+-----------+ | Id | FirstName | +------+-----------+ | 10 | John | ... Read More
76 Views
To view the indexes, you can use SHOW command.Following is the syntax −show index from yourTableName;Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(20), LastName varchar(20) ); Query OK, 0 rows affected (0.46 sec)Following is the query to create an index −mysql> create index id_FirstName on DemoTable(Id, FirstName); Query OK, 0 rows affected (0.52 sec) Records : 0 Duplicates : 0 Warnings : 0Following is the query to view the indexes I have set up in MySQL −mysql> show index from DemoTable;This will produce ... Read More
1K+ Views
To work with multiple AND conditions in MySQL, following is the syntax −select *from yourTableName where yourColumnName1=yourValue1 and yourColumnName2=yourValue2 and yourColumnName3=yourValue3;Let us first create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20), StudentAge int, StudentCountryName varchar(40) ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentName, StudentAge, StudentCountryName) values('John', 23, 'US'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(StudentName, StudentAge, StudentCountryName) values('Carol', 21, 'UK'); Query OK, 1 row affected (0.15 sec) mysql> insert ... Read More