Skip to main content

Posts

Showing posts with the label MySQL

Find 2nd Highest Salary in MySQL

Find 2nd Highest Salary in MySQL Method 1: Using LIMIT This is the simplest and most commonly used method. SELECT DISTINCT salary FROM employees ORDER BY salary DESC LIMIT 1 OFFSET 1; Note: This returns the second highest unique salary. Method 2: Using Subquery This method is easy to understand and works reliably. SELECT MAX(salary) AS second_highest FROM employees WHERE salary < (SELECT MAX(salary) FROM employees); Method 3: Using DENSE_RANK() (MySQL 8+) This method is useful for advanced queries and interviews. SELECT salary FROM ( SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rnk FROM employees ) t WHERE rnk = 2; Notes DISTINCT removes duplicate salaries If all salaries are the same, the result may be NULL Assumes table structure:  employees(salary)   Further Reading   SQL Query Simulator for the employees database SQL Query Online Simulator – Run & Practice SQL in Browser 

MySQL Query Online Simulator – Run & Practice SQL in Browser

SQL Query Online Simulator – Run & Practice SQL in Browser SELECT * FROM customers Run Export CSV Chart Dark Query History How to Use This Simulator Write your SQL query in the input box. Click Run to execute the query. View results in the table below. Use Export CSV to download results. Use Chart to visualize data. Click previous queries from history to reuse them. 📘 Sample SQL Commands SELECT * FROM customers WHERE example - SELECT * FROM customers WHERE Country='Germany' INSERT example - INSERT INTO customers VALUES ('John','Delhi','India') UPDATE example - UPDATE customers SET City='Mumbai' WHERE CustomerID=1 DELETE example - DELETE FROM customers WHERE CustomerID=2

Node.js : Brief Introduction & How to retrieve data from database

  Question: You're looking for manufacturing company suppliers in a database. Supplier identification numbers are stored in the supplier_id column. What is the proper clause to retrieve only information about the supplier with the ID number 85317? See the Answer Why are the Mongodb, Mariadb, and other databases used? You are aware that we must save our data; for example, if you own a retail store, you are aware that you must gather various data from customers and keep a record of each customer's billing. This also makes it easier to keep track of sales over time. You may also need to examine data in order to improve your business. We used to write it down with a pen and paper back in the day. However, in today's shopping malls and other types of stores, we use excel sheets to keep track of sales, customer information, and so on. One thing remains constant from the old days and now, when data is being collected. For our businesses, we're putting together a database. In ...


Contact Us

Name

Email *

Message *