Found 6702 Articles for Database

Condition to check for due date and current date records in MySQL where clause

AmitDiwan
Updated on 11-Dec-2020 05:57:50

544 Views

To check for such conditions, use IF() in MySQL.Let us create a table −Examplemysql> create table demo89    -> (    -> duedate date    -> ); Query OK, 0 rows affected (0.78Insert some records into the table with the help of insert command −Examplemysql> insert into demo89 values('2020-01-10'); Query OK, 1 row affected (0.55 mysql> insert into demo89 values(null); Query OK, 1 row affected (0.13 mysql> insert into demo89 values('2020-11-29'); Query OK, 1 row affected (0.15 mysql> insert into demo89 values('2019-11-29'); Query OK, 1 row affected (0.09Display records from the table using select statement −Examplemysql> select ... Read More

Creating a table with MySQL - Hibernate

AmitDiwan
Updated on 11-Dec-2020 05:55:53

2K+ Views

To create a table, you need to insert below line into application.properties −spring.jpa.hibernate.ddl-auto=updateHere, Hibernate will create the table demo88 automatically. The application.properties code is as follows −spring.datasource.platform=mysql spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect spring.jpa.hibernate.ddl-auto=update server.port=8191 spring.datasource.driverClassName=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/sampledatabase spring.datasource.username=root spring.datasource.password=123456The demo88 entity class is as follows to create table columns −Examplepackage com.automaticallytablecreation; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table public class demo88 {    @Id    private int id;    @Column(name="name")    private String name; }The main class code is as follows −Examplepackage com.automaticallytablecreation; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class AutomaticTableApplication {    public static void main(String[] ... Read More

Display MySQL table values using Java

AmitDiwan
Updated on 11-Dec-2020 05:50:52

4K+ Views

For this, you can use the ResultSet concept. For connection, we will be using the MySQL JDBC Driver.Let us create a table −Examplemysql> create table demo87    -> (    -> name varchar(20),    -> age int    -> )    -> ; Query OK, 0 rows affected (0.62Insert some records into the table with the help of insert command −Examplemysql> insert into demo87 values('John', 21); Query OK, 1 row affected (0.15 mysql> insert into demo87 values('David', 23); Query OK, 1 row affected (0.12 mysql> insert into demo87 values('Bob', 22); Query OK, 1 row affected (0.16Display records from ... Read More

How to check if any value is Null in a MySQL table single row?

AmitDiwan
Updated on 11-Dec-2020 05:47:37

478 Views

For this, you can use ISNULL in MySQL.Let us create a table −Examplemysql> create table demo86    -> (    -> value1 varchar(20)    -> ,    -> value2 varchar(20)    -> ); Query OK, 0 rows affected (2.77Insert some records into the table with the help of insert command −Examplemysql> insert into demo86 values(null, null); Query OK, 1 row affected (0.34 mysql> insert into demo86 values(null, 'John'); Query OK, 1 row affected (0.16 mysql> insert into demo86 values('David', 'Mike'); Query OK, 1 row affected (0.17 mysql> insert into demo86 values('Sam', null); Query OK, 1 row affected ... Read More

MySQL - SUM rows with same ID?

AmitDiwan
Updated on 11-Dec-2020 05:44:45

8K+ Views

To sum rows with same ID, use the GROUP BY HAVING clause.Let us create a table −Examplemysql> create table demo84    -> (    -> id int,    -> price int    -> )    -> ; Query OK, 0 rows affected (0.60Insert some records into the table with the help of insert command −Examplemysql> insert into demo84 values(1, 2000); Query OK, 1 row affected (0.08 mysql> insert into demo84 values(1, 2000); Query OK, 1 row affected (0.14 mysql> insert into demo84 values(2, 1800); Query OK, 1 row affected (0.14 mysql> insert into demo84 values(2, 2200); Query ... Read More

MySQL query for INSERT INTO using values from another table?

AmitDiwan
Updated on 11-Dec-2020 05:42:20

793 Views

For this, use INSERT INTO SELECT statement.Let us create a table −Examplemysql> create table demo82    -> (    -> id int,    -> name varchar(20)    -> ); Query OK, 0 rows affected (2.06Insert some records into the table with the help of insert command −Examplemysql> insert into demo82 values(100, 'John'); Query OK, 1 row affected (0.14 mysql> insert into demo82 values(101, 'Bob'); Query OK, 1 row affected (0.32 mysql> insert into demo82 values(101, 'David'); Query OK, 1 row affected (0.09 mysql> insert into demo82 values(101, 'Mike'); Query OK, 1 row affected (0.12 mysql> insert ... Read More

MySQL Select where values IN List string?

AmitDiwan
Updated on 11-Dec-2020 05:39:59

4K+ Views

For this, use FIND_IN_SET().Let us create a table −Examplemysql> create table demo81    -> (    -> id int not null auto_increment primary key,    -> username varchar(200)    -> ); Query OK, 0 rows affected (1.44Insert some records into the table with the help of insert command −Examplemysql> insert into demo81(username) values('John, Chris, David'); Query OK, 1 row affected (0.11 mysql> insert into demo81(username) values('Mike, Sam'); Query OK, 1 row affected (0.14 mysql> insert into demo81(username) values('Chris, Bob, Sam'); Query OK, 1 row affected (0.13 mysql> insert into demo81(username) values('Mike, John, Chris'); Query OK, 1 row ... Read More

Show date like 30-04-2020 instead of 2020-04-30 from MySQL database?

AmitDiwan
Updated on 11-Dec-2020 05:38:01

46 Views

For this, use DATE_FORMAT() in MySQL. The syntax is as follows −Exampleselect date_format(yourColumnName, '%d-%m-%Y') as anyAliasName from yourTableName;Let us create a table −Examplemysql> create table demo80    -> (    -> due_date date    -> ); Query OK, 0 rows affected (0.74Insert some records into the table with the help of insert command −Examplemysql> insert into demo80 values('2020-04-30'); Query OK, 1 row affected (0.14 mysql> insert into demo80 values('2016-01-10'); Query OK, 1 row affected (0.17 mysql> insert into demo80 values('2018-03-21'); Query OK, 1 row affected (0.12Display records from the table using select statement −Examplemysql> select *from demo80;This will ... Read More

Split a column in 2 columns using comma as separator - MySQL

AmitDiwan
Updated on 11-Dec-2020 05:35:52

3K+ Views

For this, you can use substring_index() in MySQL. Let us create a table −Examplemysql> create table demo79    -> (    -> fullname varchar(50)    -> ); Query OK, 0 rows affected (0.64Insert some records into the table with the help of insert command −Examplemysql> insert into demo79 values("John, Smith"); Query OK, 1 row affected (0.09 mysql> insert into demo79 values("David, Miller"); Query OK, 1 row affected (0.11 mysql> insert into demo79 values("Chris, Brown"); Query OK, 1 row affected (0.07Display records from the table using select statement −Examplemysql> select *from demo79;This will produce the following output −Output+--------------+ | ... Read More

How to get username using ID from another table in MySQL database?

AmitDiwan
Updated on 11-Dec-2020 05:33:37

2K+ Views

To get username using ID from two tables, you need to use JOIN and join the tables.Let us create a table −Examplemysql> create table demo77    -> (    -> userid int not null primary key,    -> username varchar(20)    -> ); Query OK, 0 rows affected (2.63Insert some records into the table with the help of insert command −Examplemysql> insert into demo77 values(1, 'John'); Query OK, 1 row affected (0.19 mysql> insert into demo77 values(2, 'Bob'); Query OK, 1 row affected (0.36Display records from the table using select statement −Examplemysql> select *from demo77;This will produce the following ... Read More

Advertisements