Wednesday, February 26, 2025

5 Ways to find the Second Highest Salary of Employee in SQL [Solved]

 Hello guys, if you have attended programming or software development interview then you may have come across SQL queries. In the past, I have shared popular SQL queries from interviews and one of them is how to find the 2nd highest salary of employee in SQL. This is probably the most popular SQL query question I have come across in my career and I have seen it many times. When I first come across this one I have hard time to solve it but over the years, I have learned several ways to solve this problem and find the 2nd highest or even 3rd highest salary in SQL. Earlier, I have shared how to find Nth highest salary and in this article, I am going to share 5 different ways to find the second highest salary in SQL. 

Difference between JOIN and SUBQUERY in SQL

Hey there! Ever found yourself at the crossroads of JOIN and SUBQUERY, wondering which path to take in your database adventures? Well, you're not alone! Today, I'm here to help you decipher the intriguing differences between these SQL techniques.

Difference between ISNULL and COALESCE in SQL Server

Hey there! Today, I'm diving deep into the fascinating world of SQL Server to unravel the mysteries of two essential functions: ISNULL and COALESCE. You've probably encountered these in your SQL adventures, but do you know when to use one over the other? Join me as I break it down.

Saturday, February 22, 2025

How to join two tables in a single SQL query? MySQL Example

Hello guys, if you are wondering how to join multiple tables in SQL to produce a combine result which contains columns from all tables but not sure how to do it then you have come to the right place. SQL Join is one of the basic concepts while working in databases or tables but yet less understood and most confusing topic for beginners and even intermediate developers. I compare Joins in SQL  with Recursion in programming in terms of confusion because I have found that these two topics are special in their nature and you can't get it right with casual reading until you understand the concept and its various well.

Thursday, February 20, 2025

How to Join Two Unrelated Tables in SQL using Cross Join? Example

 In one of the recent programming job interviews, one of my readers was asked the question, how do you join two tables which are not related to each other? i.e. they don't have any common column? is it possible in SQL? My reader got confused because he only knows about INNER join and OUTER join which require a key column like dept_id which is the primary key in one table like Department and foreign key in another table like Employee. He couldn't answer the question, though he did tell them about you can select data from multiple tables by typing multiple table names in from clause using a comma. 

Wednesday, February 19, 2025

Difference between Candidate Key vs Primary Key in Database/SQL

What is the difference between primary key and candidate key is another popular SQL and database interview question which appears in various programming interviews now and then? The concept of primary key and candidate key is not just important from the interview point of view but also in designing databases and normalization. By the way, this is my second post about primary keys, In the last one, we have seen a comparison of primary key vs unique key, which also happens to be one of the frequently asked database questions.

Tuesday, February 18, 2025

What is Difference between Clustered vs Non-Clustered Indexes in a table? [SQL Interview Question]

Hello guys, what is he difference between Clustered and Non-clustered index in a relational database is one of the most popular SQL interview questions almost as popular as the primary key vs unique key, the difference between truncate and delete, and correlated vs noncorrelated subqueries. Indexes are a very important concept, it makes your queries run fast and if you compare a SELECT query which uses an indexed column to one who doesn't you will see a big difference in performance.

Thursday, February 13, 2025

Top 10 SQL Server Functions Programmer Should Learn (with Examples)

Hey there! SQL Server functions are like magic spells in the enchanted forest of databases. They can transform your data and make it dance to your tune. In this article, I'm going to share my top 10 SQL Server functions that every programmer should have in their toolkit.

How to use rank, row_number, and dense_rank in SQL? Example

 Hey folks, ever found yourself at a data party, trying to figure out the pecking order? Well, I've been there too, and SQL has some nifty moves to help you out. Today, I'm going to show you how to use RANK, ROW_NUMBER, and DENSE_RANK in SQL to sort and analyze your data like a pro.

10 SQL commands every Programmer should learn

Hey there! If you're diving into the world of databases, SQL (Structured Query Language) is your golden ticket to handle and manipulate data. It's like learning the secret handshake to the programming club. In this article, I'll share the top 10 SQL commands that every programmer should have in their toolbox.

Saturday, February 8, 2025

Difference between CHAR and VARCHAR in SQL

Hey, folks! Today, we're diving into the fascinating world of SQL data types, specifically, the showdown between CHAR and VARCHAR. It's a bit like choosing between a sturdy old book (CHAR) and a flexible e-reader (VARCHAR). So, grab your virtual coffee, and let's unravel the mystery behind these two SQL heavyweights.

10 Ways to use GROUP BY command in SQL with Examples

Hey there! If you've ever waded into the wonderful world of SQL, you'll know it's a bit like orchestrating a symphony of data. And one of the most beautiful instruments in this orchestra is the GROUP BY command. So, let's take a stroll down memory lane (or should I say data lane?) as I share the ten fantastic ways I fell in love with GROUP BY.