Friday, March 21, 2025

How to Fix java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test [Solved]

The error "java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test" occurs when you try to connect MySQL database running on your localhost, listening on port 3306 port from Java program but either you don't have MySQL JDBC driver in your classpath or driver is not registered before calling the getConnection() method. Since JDBC API is part of JDK itself, when you write a Java program to connect any database like MySQL, SQL Server, or Oracle, everything compiles fine, as you only use classes from JDK but at runtime, when the JDBC driver which is required to connect to the database is not available, JDBC API either throws this error or "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver".

Wednesday, December 25, 2024

Top 5 Udemy Courses to Learn MySQL in 2025 - Best Of Lost

Hello guys, if you are interested in learning SQL with MySQL database and looking for some awesome resources e.g. books, tutorials, and online courses then you have come to the right place. In past, I have shared some useful books and tutorials and in this article, I am going to talk about some of the best MySQL online courses from Udemy, Coursera, and Pluralsight which you can join to learn SQL and MySQL from the comfort of your office or home. In the last couple of years, you might have heard the statement that everybody should learn to code, which is great. Coding is now like reading, writing, and speaking skills and in today's Information technology-centric world it is a must-have and there is no better way to start coding than learning SQL, the most popular programming language.

Tuesday, September 24, 2024

Top 10 SQL SELECT Query Examples for Beginners

The Select command in SQL is one of the most powerful and heavily used commands. This is I guess the first command anyone learns in SQL even before CREATE which is used to create a table in SQL. SELECT is used in SQL to fetch records from database tables and you can do a lot many things using Select. For example, you can select all records, you can select few records based on the condition specified in the WHERE clause, select all columns using the wild card (*) or only selecting a few columns by explicitly declaring them in a query.

Monday, September 16, 2024

Difference between LEFT and RIGHT OUTER Joins in SQL - MySQL Join example

There are two kinds of OUTER joins in SQL, LEFT OUTER join and RIGHT OUTER join. The main difference between RIGHT OUTER joins and LEFT OUTER join, as their name suggests, is the inclusion of non-matched rows. Sine INNER join only include matching rows, where the value of the joining column is the same, in the final result set, but OUTER join extends that functionality and also include unmatched rows in the final result. LEFT outer join includes unmatched rows from the table written on the left of the join predicate. 

Monday, April 8, 2024

4 Ways to find Nth highest salary in SQL - Oracle, MSSQL and MySQL

One of the most common SQL interview questions is to find the Nth highest salary of employees, where N could be 2, 3, 4 or anything e.g. find the second highest salary in SQL. Sometimes this question is also twisted as to find the nth minimum salary in SQL. Since many Programmers only know the easy way to solve this problem e.g. by using SQL IN clause, which doesn't scale well, they struggle to write the SQL query when the Interviewer keeps asking about the 4th highest, 5th highest and so on. In order to solve this problem effectively, you need to know about some key concepts like a correlated subquery, window functions like ROW_NUMER(), RANK(), and DENSE_RANK()etc. Once you know the generic logic to solve this problem, you can tackle all those variations by yourself.

Sunday, September 3, 2023

Spring Boot + MySQL Database example (CRUD) in Java [Tutorial]

Hello guys, if you are a Java developer and wondering how to connect to MySQL database from Spring Boot Java application then you have come to the right place. In this series of Spring Boot tutorials, earlier, I have shared how to use Redis with Spring Boot, a NoSQL database and in this article, I Am going to share how to connect to a relational database like MySQL with Spring Boot. I have also shared tutorials like Spring Boot + MyBatis, Spring Boot + React.js, and Spring Boot +Angular app for full-stack Java developers. If you haven't checked them then you can also check them out along the way. 

Friday, July 14, 2023

How to find duplicate records in a table on database - SQL tips

How to find duplicate records in a table is a popular SQL interview questions which have been asked as many times as difference between truncate and delete in SQL or finding second highest salary of employee. Both of these SQL queries are must know for any one who is appearing on any programming an interview where some questions on database and SQL are expected. In order to find duplicate records in the database table you need to confirm the definition of duplicates, for example in below contact table which is suppose to store name and phone number of the contact, a record is considered to be duplicate if both name and phone number is the same but unique if either of them varies.

Thursday, July 13, 2023

How to find second highest or maximum salary of Employee in SQL - Interview question

How to find the second highest or second maximum salary of an Employee is one of the most frequently asked SQL interview questions similar to finding duplicate records in table and when to use truncate vs delete. There are many ways to find second highest salary based upon which database you are using as different database provides different feature which can be used to find the second maximum or Nth maximum salary of employee. Well this question can also be generalized with other scenario like finding second maximum age etc. In this SQL tutorial we will see different example of SELECT SQL query to find second highest salary independent of databases or you may call in ANSI SQL and other SQL queries which uses database specific feature to find second maximum salary.

SQL query to copy, duplicate or backup table in MySQL, Oracle and PostgreSQL database - SELECT * Example

Many times we need to create backup or copy of tables in databases like MySQL, Oracle, or PostgreSQL while modifying table schema like adding new columns, modifying columns, or dropping columns. Since it's always best to have a backup of a table that can be used in any event. I was looking for an easy way to create an exact copy or duplicate tables which must be the same in the schema as well as in data, similar to creating a copy of the folder. Luckily there is an easy SQL query "CREATE table table_name AS" which allows you to create an exact copy of the table by executing just one SQL query. Yes, you read it correctly, no tool is required to create a backup of the table you just need to execute an SQL query.

Sunday, July 2, 2023

How to create and call stored procedure in MySQL with IN and OUT parameters? Example Tutorial

It's hard to remember the exact syntax of, how to create a stored procedure in MySQL until you are creating and working on stored procedure frequently, simply because the syntax is not a one-liner. You need to remember the exact syntax if you are using the MySQL database from the command line. What help, in this case, is, quick examples. In the last couple of MySQL tutorial we have seen How to find the second highest salary and How to join 3 tables in one query; In this MySQL tutorial we will see a couple of examples of creating stored procedure and calling stored procedure using IN and OUT parameters. A

Tuesday, May 23, 2023

Top 30 Examples of MySQL Commands in Linux and UNIX

Hello guys, if you are working with MySQL database in Linux and looking for MySQL commands to perform common tasks like starting and stopping a MySQL server then you have come to the right place. I have been working with MySQL since last 15 years as Java developer and it was actually the first database I used in a real-world project. Since I need to work with the MySQL database daily, I compiled a list of MySQL commands which I keep handy. This saves me a lot of time while doing development and support and that's what I am going to share with you today. 

Difference between Truncate and Delete in SQL? Example

Truncate and delete in SQL are two commands which are used to remove or delete data from a table. Though quite basic in nature both SQL commands can create a lot of trouble until you are familiar with details before using it. The difference between Truncate and delete are not just important to understand perspective but also a very popular SQL interview topic which in my opinion a definite worthy topic. What makes them tricky is the amount of data. Since most Electronic trading system stores, large amounts of transactional data, and some even maintain historical data, a good understanding of delete and the truncate command is required to effectively work in that environment.

Monday, May 22, 2023

Difference between Primary key vs Foreign key in table – SQL Tutorial Example

The main difference between the Primary key and the Foreign key in a table is that it’s the same column that behaves as the primary key in the parent table and as a foreign key in a child table. For example in the Customer and Order relationship, customer_id is the primary key in the Customer table but a foreign key in the Order table. By the way, what is a foreign key in a table and the difference between Primary and Foreign key are some of the popular SQL interview questions, much like truncate vs delete in SQL or difference between correlated and noncorrelated subqueryWe have been learning key SQL concepts along with these frequently asked SQL questions and in this SQL tutorial, we will discuss what is a foreign key in SQL and the purpose of the foreign key in any table. 

What is Referential Integrity in Database or SQL - MySQL Example Tutorial

Referential Integrity is a set of constraints applied to foreign keys which prevents entering a row in the child table (where you have the foreign key) for which you don't have any corresponding row in the parent table i.e. entering NULL or invalid foreign keys. Referential Integrity prevents your table from having incorrect or incomplete relationships e.g. If you have two tables Order and Customer where Customer is parent table with primary key customer_id and Order is child table with foreign key customer_id. Since as per business rules you can not have an Order without a Customer and this business rule can be implemented using referential integrity in SQL on a relational database.

Thursday, May 11, 2023

How to Add, Modify and Drop Column with Default Value, NOT NULL Constraint – MySQL Example

How to add a column in the existing table with a default value is another popular SQL interview question asked for Junior level programming job interviews. Though syntax of SQL query to add a column with default value varies a little bit from database to database, it has always been performed using ALTER keyword of ANSI SQL. Adding columns in the existing table in the MySQL database is rather easy and straight forward and we will see an example of SQL query for MySQL database which adds a column with a default value. You can also provide constraints like NULL or NOT NULL while adding a new column in the table.

Tuesday, January 31, 2023

How to Create Auto Incremented Identity Column in SQL Server, MySQL, and Oracle? Example

Automatic incremented ID, Sequence, or Identity columns are those columns in any table whose value is automatically incremented by database based upon predefined rule. Almost all databases e.g. Microsoft SQL Server, MySQL, Oracle or Sybase supports auto-incremented identity columns but in different ways like Oracle provides a SEQUENCE object which can be used to generate automatic numbers, Microsoft SQL Server up to 2008 version provides IDENTITY() functions for a similar purpose. Sybase also has IDENTITY function but little different than SQL Server and MySQL uses auto_incremented keyword to make any numeric column auto-incremented.

Friday, August 6, 2021

How to join three tables in SQL query – MySQL Example

Three tables JOIN Example SQL
Joining three tables in a single SQL query can be very tricky if you are not good with the concept of SQL Join. SQL Joins have always been tricky not only for new programmers but for many others,  who are in programming and SQL for more than 2 to 3 years. There are enough to confuse someone on SQL JOIN ranging from various types of SQL JOIN like INNER and OUTER join, LEFT and RIGHT outer join, CROSS join, etc. Between all of these fundamentals, What is most important about Join is, combining multiple tables. If you need data from multiple tables in one SELECT query you need to use either subquery or JOIN.

SQL Query to Find All Table Names on a Database With MySQL and SQL Server Examples

How do you find names of all tables in a database is a recent  SQL interview question asked to one of my friends. There are many ways to find all table names from any database like MySQL and SQL Server. You can get table names either from INFORMATION_SCHEMA or sys.tables based upon whether you are using MySQL or SQL Server database. This is not a popular question like when to use truncate and delete or correlated vs noncorrelated subquery which you can expect almost all candidates to prepare well but this is quite common if you are working on any database like MySQL.

Thursday, August 5, 2021

How to write SubQuery in SQL? Correlated vs Noncorrelated Sub Query Example

Hello guys, if you are struggling to write a sub query in SQL and need some guidance then you have come to the right place. In this article, I will not only teach you what is subquery, how it works, and which problem it solves but also teach you how to write both correlated and non-correlated sub-queries with real-world examples. SubQuery in SQL is a query inside another query. Some time to get particular information from a database you may need to fire two separate SQL queries, subQuery is a way to combine or join them in a single query. SQL query which is on the inner part of the main query is called the inner query while the outer part of the main query is called the outer query.

Database Transaction Tutorial in SQL with Example for Beginners

A database transaction is an important concept to understand while working in databases and SQL. Transaction in the database is required to protect data and keep it consistent when multiple users access the database at the same time.  In this database transaction tutorial we will learn what is a transaction in a database, why do you need transactions in the database, ACID properties of database transactions,s and an example of database transactions along with commit and rollback.