- 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
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
334 Views
To fetch record by year, use the YEAR() method in MySQL −select *from yourTableName where year(yourColumnName)=yourYearValue;Let us first create a table −mysql> create table DemoTable -> ( -> CustomerName varchar(100), -> ShippingDate datetime -> ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', '2019-01-21'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values('Robert', '2018-02-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('David', '2016-04-01'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
2K+ Views
For this, you can use stored procedure. Let us create a table dynamically with two columns i.e. StudentId as int, whereas StudentName as varchar −mysql> DELIMITER $$ mysql> CREATE PROCEDURE creatingDynamicTableDemo(yourTableName VARCHAR(200)) -> BEGIN -> SET @name = yourTableName; -> SET @st = CONCAT(' '> CREATE TABLE IF NOT EXISTS `' , @name, '` ( '> `StudentId` int UNSIGNED NOT NULL AUTO_INCREMENT, '> `StudentName` varchar(20) NOT NULL, '> PRIMARY KEY (`StudentId`) '> ) '> '); -> PREPARE ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
176 Views
To search for an integer value in a varchar filed, you can use CASE statement.Let us first create a table. Consider, we have a list of email-ids −mysql> create table DemoTable -> ( -> Title varchar(100) -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('9John@example.com'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('3Carol@gmail.com'); Query OK, 1 row affected (0.45 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+-------------------+ | Title ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
71 Views
For this, use the COUNT() method. Let us first create a table −mysql> create table DemoTable -> ( -> ProductName varchar(100) -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Product-1'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values('Product-2'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Product-3'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Product-3'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable values('Product-2'); Query OK, 1 row affected ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
846 Views
For this, use ORDER BY MAX(). Let us first create a table −mysql> create table DemoTable -> ( -> Id int, -> Name varchar(100) -> ); Query OK, 0 rows affected (0.81 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, 'John'); Query OK, 1 row affected (0.51 sec) mysql> insert into DemoTable values(10, 'John'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(20, 'Sam'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(20, 'Sam'); Query OK, 1 row affected (0.11 sec) ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
573 Views
For this, you can use ORDER BY clause. Let us first create a table −mysql> create table DemoTable -> ( -> Num1 int, -> Num2 int -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(60, 249); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(59, 250); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+------+------+ | Num1 | Num2 | +------+------+ | 60 | 249 ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
342 Views
Let us first create a table −mysql> create table DemoTable -> ( -> StudentId varchar(100) -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('STU-090'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('STU-123'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('STU-678'); Query OK, 1 row affected (0.29 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+-----------+ | StudentId | +-----------+ | STU-090 | ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
Use the SUBSTR() method to get the substring of a column.Let us first create a table −mysql> create table DemoTable -> ( -> Title text -> ); Query OK, 0 rows affected (0.74 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('This is a MySQL Database'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Java is an Object Oriented Programming Language'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from DemoTable ;OutputThis will produce the following output −+-------------------------------------------------+ | Title ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
373 Views
Let us first create a table. One of the column is a timestamp −mysql> create table DemoTable -> ( -> CustomerName varchar(100), -> CustomerShippingDate timestamp -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', '2019-01-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('David', '2019-03-01'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('Robert', '2019-06-04'); Query OK, 1 row affected (0.25 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
395 Views
For random, use RAND() method. And for limit on rows, use the LIMIT() method.Let us first create a table −mysql> create table DemoTable -> ( -> ShippingDate datetime -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-01'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('2019-01-03'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2019-01-05'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-01-07'); Query OK, 1 row affected (0.11 sec) ... Read More