How to select the first record in a given set of rows

Select top 1 * from sales.salesperson To select the first record in a given set of rows in a database management system (DBMS), you can typically use the LIMIT clause in conjunction with the ORDER BY clause to specify the ordering of the rows. The LIMIT clause restricts the number of rows returned by the … Read more

What is “CROSS JOIN”? Orwhat is Cartesian product

CROSS JOIN” or “CARTESIAN PRODUCT” combines all rows from both tables. Number of rows will be product of the number of rows in each table. In real life scenario I can not imagine where we will want to use a Cartesian product. But there are scenarios where we would like permutation and combination probably Cartesian … Read more

What are different types of joins in SQL

INNER JOIN Inner join shows matches only when they exist in both tables. Example in the below SQL there are two tables Customers and Orders and the inner join in made on Customers.Customerid and Orders.Customerid. So this SQL will only give you result with customers who have orders. If the customer does not have order … Read more

We have an employee salary table, how do we find the second highest from it.

Below Sql Query find the second highest salary SELECT * FROM pcdsEmployeeSalary a WHERE (2=(SELECT COUNT(DISTINCT(b.salary)) FROM pcdsEmployeeSalary b WHERE b.salary>=a.salary)) To find the second highest salary from an employee salary table in a Database Management System (DBMS), you can use a query like this: sql SELECT MAX(salary) AS second_highest_salary FROM employees WHERE salary < … Read more

Can you explain the between clause

Below SQL selects employees born between ’01/01/1975′ AND ’01/01/1978′ as per mysql SELECT * FROM pcdsEmployee WHERE DOB BETWEEN ‘1975-01-01’ AND ‘2011-09-28’ Sure, the BETWEEN clause in a database management system (DBMS) is used to specify a range to test against. It’s commonly used in SQL queries to filter data within a specified range of … Read more