- 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 6702 Articles for Database
60 Views
Let us first create a table −mysql> create table DemoTable ( FirstName varchar(100) ); Query OK, 0 rows affected (0.96 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-----------+ | FirstName | ... Read More
123 Views
For this, use aggregate function count(*) to count to GROUP BY to group. Let us first create a table −mysql> create table DemoTable ( UserName varchar(100), UserPostMessage text ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 'Hi'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('David', 'Hello'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Chris', 'Awesome'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Chris', 'Amazing'); Query OK, 1 row affected (0.17 sec) mysql> insert ... Read More
60 Views
Let us first create a table −mysql> create table DemoTable ( Id int, Name varchar(100) ); Query OK, 0 rows affected (0.94 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, 'Chris'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(1, 'David'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(4, 'Bob'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(6, 'Sam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(7, 'Mike'); Query OK, 1 row affected (0.10 sec) mysql> insert ... Read More
216 Views
For this, use aggregate function MIN() along with WHERE clause. Let us first create a table −mysql> create table DemoTable ( Number int ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(11); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(9); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(12); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This ... Read More
69 Views
Let us first create a table −mysql> create table DemoTable ( UserName varchar(100) ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Smith_John'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Smith_Adam'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Smith_David'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Smith_Mike'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-------------+ | UserName ... Read More
1K+ Views
For this, you can use BETWEEN keyword. Let us first create a table −mysql> create table DemoTable ( ExpiryDate date ); Query OK, 0 rows affected (0.55 sec)Note − Let’s say the current date is 2019-08-18.Insert some records in the table using insert command −mysql> insert into DemoTable values('2018-01-21'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('2019-08-20'); Query OK, 1 row affected (0.39 sec) mysql> insert into DemoTable values('2018-08-20'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('2019-08-21'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select ... Read More
461 Views
Let us first create a table −mysql> create table DemoTable ( StudentId int, StudentMarks int ); Query OK, 0 rows affected (0.83 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1000, 78); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(1001, 88); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(1000, 89); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(1000, 67); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(1000, 90); Query OK, 1 row affected (0.21 sec) mysql> insert ... Read More
170 Views
To assign value 1 while altering, use the MySQL DEFAULT. This will itself enter 1 if nothing is inserted in the same column while using the INSERT command.Let us first create a table −mysql> create table DemoTable ( isAdult int ); Query OK, 0 rows affected (1.39 sec)Following is how you can assign value 1 default to the already created column −mysql> alter table DemoTable CHANGE isAdult isAdult BOOLEAN DEFAULT '1' NOT NULL; Query OK, 0 rows affected (1.18 sec) Records: 0 Duplicates: 0 Warnings: 0Insert some records in the table using insert command −mysql> insert into DemoTable values(); ... Read More
311 Views
To find the minimum and maximum values in a single query, use MySQL UNION. Let us first create a table −mysql> create table DemoTable ( Price int ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(88); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(98); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(120); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement ... Read More
169 Views
For this, use the FOUND_ROWS in MySQL. Following is the syntax −SELECT SQL_CALC_FOUND_ROWS TABLE_NAME FROM `information_schema`.tables WHERE TABLE_NAME LIKE "yourValue%" LIMIT yourLimitValue;Here, I am using the database ‘web’ and I have lots of tables, let’s say which begins from DemoTable29. Let us implement the above syntax to fetch only 4 of such rows −mysql> SELECT SQL_CALC_FOUND_ROWS TABLE_NAME FROM `information_schema`.tables WHERE TABLE_NAME LIKE "DemoTable29%" LIMIT 4;This will produce the following output −+--------------+ | TABLE_NAME | +--------------+ | demotable29 | | demotable290 | | demotable291 | | demotable292 | +--------------+ 4 rows in set (0.01 sec)Here is the query ... Read More