
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 4381 Articles for MySQL

9K+ Views
You can count multiple COUNT() for multiple conditions in a single query using GROUP BY.The syntax is as follows -SELECT yourColumnName, COUNT(*) from yourTableName group by yourColumnName;To understand the above syntax, let us first create a table. The query to create a table is as follows.mysql> create table MultipleCountDemo -> ( -> Id int, -> Name varchar(100), -> Age int -> ); Query OK, 0 rows affected (2.17 sec)Insert records in the table using insert command. The query is as follows.mysql> insert into MultipleCountDemo values(1, 'Carol', 21); Query OK, 1 row affected (0.27 sec) mysql> insert into MultipleCountDemo values(2, ... Read More

849 Views
In MySQL, now() can be used to insert current date/time. The syntax is as follows −insert into yourTableName values(now());To understand the above concept of inserting current date/time in the table, let us first create a table −mysql> create table CurrentDateTimeDemo −> ( −> YourTime datetime −> ); Query OK, 0 rows affected (0.58 sec)Inserting current date/time using now(). The query is as follows −mysql> insert into CurrentDateTimeDemo values(now()); Query OK, 1 row affected (0.20 sec)Now you can check the current date/time has been inserted or not −mysql> select *from CurrentDateTimeDemo;The following ... Read More

495 Views
You can use WHERE clause and OR operator to show table with multiple LIKE. The syntax is as follows:show table from yourDatabaseName where tables_in_yourDatabaseName Like ‘%anyTableName%’ or tables_in_yourDatabaseName Like ‘%anyTableName2%’ or tables_in_yourDatabaseName Like ‘%anyTableName3%’ . . . . or tables_in_yourDatabaseName Like ‘%anyTableNameN%’In the above syntax, only the table name in the database is displayed.Here the database ‘test’ and the tables in the same database is considered. The query to show tables with multiple LIKE is as follows -mysql> show tables from test -> where tables_in_test like '%userrole%' -> or tables_in_test like '%view_student%' -> or tables_in_test like '%wholewordmatchdemo%';The following is the ... Read More

1K+ Views
To update values incrementally in MySQL, you need to create a variable with the help of SET command. The syntax to create a variable is as follows −set @anyVariableName := 0;To update value, you need to use UPDATE command. Let us begin with creating a table. The query to create a table −mysql> create table UpdateValueIncrementally −> ( −> ProductId int −> ); Query OK, 0 rows affected (0.90 sec)Insert records in the table with the help of select statement. The query is as follows −mysql> insert into UpdateValueIncrementally values(10); Query ... Read More

2K+ Views
Parse date in MySQL with the help of STR_TO_DATE() function. The syntax is as follows −select str_to_date(yourColumName, ’format’) as anyVariableName from yourTableName;The format in the above syntax is '%d-%b-%y'.Now to understand the above function, let us create a table. The following is the query to create a table −mysql> create table ParseDateDemo −> ( −> yourDate varchar(200) −> ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table with the help of select statement. The query is as follows −mysql> insert into ParseDateDemo values('10-Nov-18'); Query OK, 1 row ... Read More

336 Views
To set max_connections in MySQL programmatically, you can use SET command. The syntax is as follows −SET GLOBAL max_connections=yourIntegerValue;Let us implement the above query to set maximum connections. The query is as follows −mysql> set global max_connections=1000; Query OK, 0 rows affected (0.04 sec)Check maximum connections are set or not, using the show variables command. The query is as follows.mysql> show variables like 'max_connections';The following is the output.+-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 1000 | +-----------------+-------+ 1 row in set (0.18 sec)

1K+ Views
To get the nth record from MySQL query, you can use LIMIT. The syntax is as follows −select *from yourTableName order by yourColumnName limit n, 1;To understand the above syntax, let us create a table. The following is the query to create a table −mysql> create table NthRecordDemo −> ( −> Id int, −> Name varchar(200) −> ); Query OK, 0 rows affected (0.92 sec)Insert some records in the table using the following query −mysql> insert into NthRecordDemo values(100, 'John'); Query OK, 1 row affected (0.09 sec) ... Read More

18K+ Views
You can query between dates with the help of BETWEEN statement. The syntax is as follows −select *from yourTableName where yourColumnName between ‘yourStartingDate’ and curdate().Use curdate() or now(), both these functions will work. To understand the above syntax, let us create a table −mysql> create table BetweenDateDemo −> ( −> StartDate datetime −> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table with the help of the following query −mysql> insert into BetweenDateDemo values(date_add(now(), interval -1 year)); Query OK, 1 row affected (0.11 sec) mysql> insert ... Read More

231 Views
To concat a string, use the CONCAT() function from MySQL as shown in the below syntaxSELECT CONCAT(yourColumnName1, ’anyConcatenationString’), CONCAT(yourColumnName2, ’anyC oncatenationString’), ....N from yourTableName;To understand the above syntax, let us first create a table. The query to create a table is as followsmysql> create table selectConcat -> ( -> StudentId int, -> StudentName varchar(100), -> StudentAge int -> ); Query OK, 0 rows affected (1.32 sec)Insert some records in the table using insert command. The query is as followsmysql> insert into selectConcat values(1, 'Carol', 23); Query OK, 1 row affected (0.19 sec) mysql> insert into selectConcat values(2, 'John', 24); ... Read More

419 Views
You can order by length of characters with the help of CHAR_LENGTH() function from MySQL. The function returns the number of characters i.e. 4 for the following string −AMITTo order strings by length of characters, the following is the syntax −select *from yourTableName order by CHAR_LENGTH(yourColumnName);To understand the above concept, let us first create a table. The following is the query to create a table −mysql> create table OrderByCharacterLength −> ( −> BookName varchar(200) −> ); Query OK, 0 rows affected (1.97 sec)Insert some records in the table with the help of insert command. The query is ... Read More