- 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
138 Views
For this, use CASE statement along with FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable1629 -> ( -> Month varchar(100) -> ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command.mysql> insert into DemoTable1629 values('2, 4, 6'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1629 values('1, 3, 5, 12'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1629 values('7, 8, 9, 10'); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement − mysql> select ... Read More
158 Views
For this, you can use GROUP BY MONTH(). Let us first create a table −mysql> create table DemoTable1628 -> ( -> PurchaseDate date, -> Amount int -> ); Query OK, 0 rows affected (1.55 sec)Insert some records in the table using insert command.mysql> insert into DemoTable1628 values('2019-01-10', 1500); Query OK, 1 row affected (0.68 sec) mysql> insert into DemoTable1628 values('2019-10-10', 2000); Query OK, 1 row affected (0.61 sec) mysql> insert into DemoTable1628 values('2019-10-24', 100); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1628 values('2019-11-10', 500); Query OK, 1 row affected ... Read More
697 Views
To set default, you can use the DEFAULT keyword in MySQL. Let us first create a table −mysql> create table DemoTable -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(20), -> EmployeeJoiningDate datetime default '0000-00-00 00:00:00' -> )ENGINE=MyISAM, AUTO_INCREMENT=100; Query OK, 0 rows affected (0.21 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(EmployeeName) values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(EmployeeName) values('David'); Query OK, 1 row affected (0.04 sec) mysql> insert into DemoTable(EmployeeName) values('Mike'); Query OK, 1 row affected (0.03 sec) mysql> ... Read More
647 Views
Set the JDBC MySQL URL in the DriverManager.getConnection to connect with IP Address. Following is the code to connect using IP Address −Exampleimport java.sql.Connection; import java.sql.DriverManager; public class JavaIP { public static void main(String[] args) { String hostURL = "jdbc:mysql://192.168.43.144:3306/web?useSSL=false"; Connection con = null; try { con = DriverManager.getConnection(hostURL, "root", "123456"); System.out.println("connection successful via ip address"); } catch (Exception e) { e.printStackTrace(); } } }OutputThis will produce the following output −connection successful via ip addressHere is the snapshot of the output −
966 Views
For this, you can use IF() along with aggregate function SUM(). Let us first create a table −mysql> create table DemoTable1617 -> ( -> Attendance varchar(20), -> CurrentYear int -> ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1617 values('Present', 2019); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1617 values('Absent', 2019); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1617 values('Absent', 2017); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1617 values('Present', 2019); Query ... Read More
326 Views
For this, you can use AND operator with WHERE clause. Let us first create a table −mysql> create table DemoTable1616 -> ( -> StudentId int, -> StudentName varchar(20), -> StudentMarks int -> ); Query OK, 0 rows affected (0.44 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1616 values(101, 'Chris', 56); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1616 values(102, 'Bob', 87); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1616 values(103, 'David', 56); Query OK, 1 row affected (0.20 sec) ... Read More
434 Views
For this, use SUBSTRING_INDEX(). Let us first create a table −mysql> create table DemoTable1615 -> ( -> ListOfSubject text -> ); Query OK, 0 rows affected (0.81 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1615 values('Python, Java, MySQL, MongoDB, C, C++, ASP.net'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select * from DemoTable1615; This will produce the following output −+-----------------------------------------+ | ListOfSubject | +-----------------------------------------+ | Python, Java, MySQL, MongoDB, C, ... Read More
66 Views
Let us first create a table −mysql> create table DemoTable1614 -> ( -> StudentName varchar(20), -> StudentScore int -> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1614 values('Adam', 65); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1614 values('Chris', 89); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1614 values('Bob', 58); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1614 values('Sam', 98); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1614 values('Mike', 87); Query OK, 1 ... Read More
697 Views
Yes, you can use DATE() to get only date part in MySQL and you can use CURDATE() to get the current date in MySQL.The current date is as follows −mysql> select curdate(); +------------+ | curdate() | +------------+ | 2019-10-20 | +------------+ 1 row in set (0.00 sec)Let us first create a table −mysql> create table DemoTable1613 -> ( -> PostingDate datetime -> ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1613 values('2019-10-20 12:02:45'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1613 values('2018-10-20 12:02:45'); ... Read More
112 Views
MySQL AND is used in WHERE to fetch a record by filtering using multiple conditions. Let us first create a table−mysql> create table DemoTable -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(101, 'Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(102, 'David'); Query OK, 1 row affected (0.51 sec) mysql> insert into DemoTable values(103, 'Bob'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement ... Read More