- 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
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
259 Views
You need to use INFORMATION_SCHEMA.SCHEMATA for current default database collation.The syntax is as followsSELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = 'yourDatabaseName' LIMIT 1;Let us implement the above syntax to discover current default database collation (via command line client). Our database here is ‘sample’.The query is as follows −mysql> SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = 'sample' LIMIT 1;The following is the output+------------------------+ | DEFAULT_COLLATION_NAME | +------------------------+ | utf8_general_ci | +------------------------+ 1 row in set (0.00 sec)
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
560 Views
To understand the concept, let us first create a demo table.mysql> create table addToExistingValueDemo -> ( -> Instructor_Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Instructor_Name varchar(30), -> Instructor_TechnicalSubject text -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into addToExistingValueDemo(Instructor_Name, Instructor_TechnicalSubject) values('John', 'C, C++'); Query OK, 1 row affected (0.15 sec) mysql> insert into addToExistingValueDemo(Instructor_Name, Instructor_TechnicalSubject) values('Carol', 'Java, Python'); Query OK, 1 row affected (0.18 sec) mysql> insert into addToExistingValueDemo(Instructor_Name, Instructor_TechnicalSubject) values('Bob', 'MySQL, SQL Server'); Query OK, 1 row ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
To count boolean field values within a single query, you can use CASE statement. Let us create a demo table for our example −mysql> create table countBooleanFieldDemo -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentFirstName varchar(20), -> isPassed tinyint(1) -> ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into countBooleanFieldDemo(StudentFirstName, isPassed) values('Larry', 0); Query OK, 1 row affected (0.12 sec) mysql> insert into countBooleanFieldDemo(StudentFirstName, isPassed) values('Mike', 1); Query OK, 1 row affected (0.17 sec) mysql> insert into ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
414 Views
To avoid inserting duplicate rows in MySQL, you can use UNIQUE(). The syntax is as follows −ALTER TABLE yourTableName ADD UNIQUE(yourColumnName1, yourColumnName2, ...N);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table avoidInsertingDuplicateRows -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> FirstValue int, -> SecondValue int -> ); Query OK, 0 rows affected (0.53 sec)Now check the description of table using desc command. The query is as follows −mysql> desc avoidInsertingDuplicateRows;Sample The following is The output −+-------------+---------+------+-----+---------+----------------+ | Field ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
836 Views
The desc is a MySQL reserved word, therefore you cannot use it. But, if you still want to set the column name as ‘desc’, you need to use backticks. The backtick notation is (` `).To understand the above concept, let us create a table. The query to create a table is as follows −mysql> create table useOfDescColumnNameDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20), -> `desc` varchar(200) default 'GOOD' -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command. The query is as follows ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
To create a view only if it does not already exist, you can use the following syntax −CREATE OR REPLACE VIEW yourViewName AS SELECT *FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table createViewDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name 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 createViewDemo(Name) values('John'); Query OK, 1 row affected (0.22 sec) mysql> insert into ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
801 Views
The syntax is as follows to count all characters in all rows of a field −select sum(char_length(yourColumnName)) AS anyAliasName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table CountAllCharactersDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(20), -> UserSubject text -> ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into CountAllCharactersDemo(UserName, UserSubject) values('Larry', 'Introduction To Java'); Query OK, 1 row affected (0.19 ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
The syntax is as follows to trim commas −SELECT TRIM(BOTH ', ' FROM yourColumnName) from yourTableName;Let us see an example −mysql> create table TrimCommasDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> AllTechnicalSkills text -> ); Query OK, 0 rows affected (0.81 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into TrimCommasDemo(AllTechnicalSkills) values(', C, C++, Java, '); Query OK, 1 row affected (0.14 sec) mysql> insert into TrimCommasDemo(AllTechnicalSkills) values(', MySQL, SQL Server, MongoDB, '); Query OK, 1 row affected (0.13 sec) mysql> ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
221 Views
You can use CASE statement for this. Let us see an example −mysql> create table BooleanEvaluationDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> FirstValue int, -> SecondValue int -> ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into BooleanEvaluationDemo(FirstValue, SecondValue) values(10, 5); Query OK, 1 row affected (0.20 sec) mysql> insert into BooleanEvaluationDemo(FirstValue, SecondValue) values(15, 20); Query OK, 1 row affected (0.16 sec) mysql> insert into BooleanEvaluationDemo(FirstValue, SecondValue) values(50, 40); Query OK, 1 row affected (0.14 ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
The syntax is as follows to skip the duplicate value and select only one from the duplicated values −select min(yourColumnName1), yourColumnName2 from yourTableName group by yourColumnName2;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table doNotSelectDuplicateValuesDemo -> ( -> User_Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> User_Name varchar(20) -> ); Query OK, 0 rows affected (0.78 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into doNotSelectDuplicateValuesDemo(User_Name) values('John'); Query OK, 1 row affected ... Read More