- 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 4378 Articles for MySQL
49 Views
If you do not want to include start and end value in between, then use the following syntax −SELECT * FROM yourTableName WHERE yourColumnName BETWEEN yourStartingValue and yourEndingValue and yourColumnName not in (yourStartingValue , yourEndingValue );To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table BetweenWithoutEndPoints -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(20), -> Age int, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.54 sec)Now you can insert some records in the table using ... Read More
152 Views
If you do not want to include the end value in between, then use the following syntax −SELECT * FROM yourTableName WHERE yourColumnName BETWEEN yourStartingValue and yourEndingValue and yourColumnName not in (yourEndingValue );To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table BetweenWithoutEndPoints -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(20), -> Age int, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.54 sec)Now you can insert some records in the table using insert command. The ... Read More
141 Views
The best data type for currencies in MySQL is a DECIMAL. The syntax of DECIMAL data type is as follows −DECIMAL(TotalDigit, NumberOfDigitAfterDecimalPoint);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table CurrenciesDemo -> ( -> TotalPrice DECIMAL(10, 2) -> ); Query OK, 0 rows affected (1.82 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into CurrenciesDemo values(1647575.67); Query OK, 1 row affected (0.19 sec) mysql> insert into CurrenciesDemo values(1647575); Query OK, 1 row affected (0.21 sec) ... Read More
2K+ Views
You can use GROUP BY command for select with distinct id. The syntax is as follows −SELECT *FROM yourTableName GROUP BY yourColumnName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table DistinctIdDemo -> ( -> Id int, -> Name varchar(20), -> Age int -> ); Query OK, 0 rows affected (1.03 sec)Insert some records in the table using insert command. Here, we have added ID with duplicate values.The query is as follows −mysql> insert into DistinctIdDemo values(1, 'Mike', 23); Query OK, 1 row ... Read More
1K+ Views
No, definer part is not compulsory when you are creating a stored procedure. It is used when you want to create a definer.Check all the user and host from the MySQL.user table −mysql> select user, host from mysql.user;The following is the output −+------------------+-----------+ | user | host | +------------------+-----------+ | Manish | % | | User2 | % | | mysql.infoschema | % | | mysql.session | % ... Read More
533 Views
You need to use cast() method to perform comparison on an INT field. The syntax is as follows −SELECT yourColumnName1, yourColumnName2, ......N yourTableName WHERE CAST(yourColumnName as CHAR) LIKE ‘%yourIntegerValue%’;To understand the above syntax, let us create a table. The following is the query to create a table for performing a LIKE comparison on INT field −mysql> create table ComparisonOnIntField -> ( -> StudentId int NOT NULL, -> StudentName varchar(20), -> StudentAge int -> ); Query OK, 0 rows affected (1.00 sec)Insert some records in the table to perform a MySQL LIKE comparison on an INT ... Read More
5K+ Views
To query a list of values, you can use IN operator. The syntax is as follows −SELECT * FROM yourTableName WHERE yourColumnName IN(Value1, Value2, ...N) ORDER BY FIELD(yourColumnName, Value1, Value2, ...N);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ListOfValues -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(30), -> Age int, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.72 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert ... Read More
12K+ Views
You can add static value when you use INSERT INTO SELECT MySQL query. Write the value directly in the select statement or you can add with the help of variable which initializes the value.Case 1 − Place the value directly in the INSERT INTO SELECT statement. The syntax is as follows −INSERT INTO yourSecondTableName(yourColumnName1, yourColumnName2, ....N) SELECT yourColumnName1 ,yourColumnName2, .....N, yourStaticValue from yourFirstTableName;Case 2 − Add using variable. The syntax is as follows −SET @yourVariableName − = yourstaticValue; INSERT INTO yourSecondTableName(yourColumnName1, yourColumnName2, ....N) SELECT yourColumnName1 ,yourColumnName2, .....N, @yourVariableName from yourFirstTableName;To understand the above syntax, you need to ... Read More
15K+ Views
You can use ORDER BY RIGHT() function to order by last 3 chars in MySQL. The syntax is as follows −SELECT *FROM yourTableName ORDER BY RIGHT(yourColumnName, 3) yourSortingOrder;Just replace the ‘yourSortingOrder’ to ASC or DESC to set the ascending or descending order respectively.To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table OrderByLast3Chars -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT, -> EmployeeName varchar(20), -> EmployeeAge int, -> PRIMARY KEY(EmployeeId) -> ); Query OK, 0 rows affected (0.56 sec)Insert some records in ... Read More
930 Views
You can quote values using concat() and grop_concat() function from MySQL. The syntax is as follows −SELECT GROUP_CONCAT(CONCAT(' '' ', yourColumnName, ' '' ' )) as anyVariableName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table Group_ConcatDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Value int, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (1.56 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into Group_ConcatDemo(Value) ... Read More