- 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
99 Views
To configure a DataSource in Springboot, you can define DataSource into application.properties.The application.properties is as follows for Springboot −spring.datasource.username=yourUserName spring.datasource.password=yourPassword spring.datasource.url=yourDatabaseUrl spring.datasource.driver-class-name=yourDriverClassNameThe project structure is as follows −ExampleTo understand the above concept, let us create a controller class with spring boot. The Java code is as follows −package com.demo.controller; import java.util.List; import javax.persistence.EntityManager; import javax.persistence.Query; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/users") public class DisplayController { @Autowired EntityManager entityManager; @GetMapping("/getdata") public String getAll() { Query data= entityManager.createNativeQuery("select first_name from demo25"); List allData= data.getResultList(); return ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
To set default value, use the DEFAULT constraint as in the below syntax −alter table yourTableName modify column yourColumnName JSON NOT NULL DEFAULT ( JSON_OBJECT() );Let us create a table −mysql> create table demo24 −> ( −> employee_information text −> ) −> ; Query OK, 0 rows affected (1.43 sec)Here is the description of table. Following is the query −mysql> desc demo24;This will produce the following output −+----------------------+------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------------+------+------+-----+---------+-------+ | employee_information | text | YES | | NULL ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
190 Views
For this, use aggregate function COUNT(*) along with subquery. GROUP BY is also used.Let us create a table −mysql> create table demo23 −> ( −> id int not null auto_increment primary key, −> value1 int, −> value2 int −> ); Query OK, 0 rows affected (1.65 sec)Insert some records into the table with the help of insert command −mysql> insert into demo23(value1, value2) values(5, 600); Query OK, 1 row affected (0.20 sec) mysql> insert into demo23(value1, value2) values(20, 800); Query OK, 1 row affected (0.06 sec) mysql> insert into demo23(value1, value2) values(7, 400); Query OK, 1 row affected ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
103 Views
For this, use left join on table A and B. Let us create the first table −mysql> create table demo20 −> ( −> id int, −> name varchar(20) −> ); Query OK, 0 rows affected (1.87 sec)Insert some records into the table with the help of insert command −mysql> insert into demo20 values(100, 'John'); Query OK, 1 row affected (0.07 sec) mysql> insert into demo20 values(101, 'Bob'); Query OK, 1 row affected (0.24 sec) mysql> insert into demo20 values(102, 'Mike'); Query OK, 1 row affected (0.12 sec) mysql> insert into demo20 values(103, 'Carol'); Query OK, 1 row ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
520 Views
Following is the correct syntax to use LIKE with search variable −String sqlQuery; sqlQuery = "select *from yourTableName where yourColumnName like '%" +yourSearchVariableName + "%'";Let us create a table −mysql> create table demo19 −> ( −> id int not null auto_increment primary key, −> name varchar(50) −> ); Query OK, 0 rows affected (3.48 sec)Insert some records into the table with the help of insert command −mysql> insert into demo19(name) values('John Smith'); Query OK, 1 row affected (0.15 sec) mysql> insert into demo19(name) values('David Miller'); Query OK, 1 row affected (0.15 sec) mysql> insert into demo19(name) values('Adam Smith'); ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
610 Views
Use ORDER BY with some cases. Let us create a table −mysql> create table demo18 −> ( −> value text −> ); Query OK, 0 rows affected (1.18 sec)Insert some records into the table with the help of insert command −mysql> insert into demo18 values('John Smith'); Query OK, 1 row affected (0.06 sec) mysql> insert into demo18 values('2J John has 58'); Query OK, 1 row affected (0.17 sec) mysql> insert into demo18 values('2J John has 9'); Query OK, 1 row affected (0.09 sec)Display records from the table using select statement −mysql> select *from demo18;This will produce the following ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
249 Views
To combine SELECT and SHOW command results into one, use the below query −select @anyVariableName1 as anyAliasName1, @anyVariableName1 as anyAliasName2, ......N;To combine the SELECT and SHOW, first create and initialize the first variable. Following is the query −mysql> set @first_name='John'; Query OK, 0 rows affected (0.00 sec)To combine the SELECT and SHOW, create and initialize the second variable. Following is the query −mysql> set @last_name='Smith'; Query OK, 0 rows affected (0.00 sec)Following is the query to combine the SELECT and SHOW command −mysql> select @first_name as EmployeeFirstName, @last_name as EmployeeLastName;This will produce the following output −+-------------------+------------------+ | EmployeeFirstName | EmployeeLastName ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
349 Views
To search in a comma separated list, use MySQL find_in_set(). The usage of Regex for this purpose isn’t required here. The syntax is as follows −select *from yourTableName where find_in_set(anyValue, yourColumnName);Let us create a table −mysql> create table demo17 −> ( −> id int not null auto_increment primary key, −> first_name varchar(50), −> value text −> ); Query OK, 0 rows affected (1.81 sec)Insert some records into the table with the help of insert command −mysql> insert into demo17(first_name, value) values('John', '50'); Query OK, 1 row affected (0.11 sec) mysql> insert into demo17(first_name, value) values('David', ''); Query OK, 1 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
199 Views
Extract using extract() method along with cast(). Following is the syntax −select extract(minute from cast(yourColumnName as time)) as anyAliasName from yourTableName;Let us create a table −mysql> create table demo15 −> ( −> value time −> ); Query OK, 0 rows affected (2.11 sec)Insert some records into the table with the help of insert command −mysql> insert into demo15 values('10:30:45'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo15 values('06:34:55'); Query OK, 1 row affected (0.17 sec)Display records from the table using select statement −mysql> select *from demo15;This will produce the following output −+----------+ | value ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
342 Views
To delete duplicate columns, use DELETE with INNER JOIN. Following is the syntax −delete tbl1 from yourTableName anyAliasName1 inner join yourTableName anyAliasName2 where yourCondition1 and yourCondition2Let us create a table −mysql> create table demo14 −> ( −> id int not null auto_increment primary key, −> name varchar(30) −> ); Query OK, 0 rows affected (1.89 sec)Insert some records into the table with the help of insert command −mysql> insert into demo14(name) values('John'); Query OK, 1 row affected (0.14 sec) mysql> insert into demo14(name) values('David'); Query OK, 1 row affected (0.18 sec) mysql> insert into demo14(name) values('David'); Query OK, ... Read More