You are on page 1of 2

SQL Interview Questions:

Question: Retrieve the names of all employees who have not been assigned to any project.
Answer: You can use the following SQL query: SELECT employee_name FROM employees
WHERE employee_id NOT IN (SELECT DISTINCT employee_id FROM projects);

Question: Calculate the average salary of employees in each department.


Answer: Here's the query: SELECT department_id, AVG(salary) FROM employees GROUP BY
department_id;

Question: List the top 3 highest-paid employees along with their salaries.
Answer: Use: SELECT employee_name, salary FROM employees ORDER BY salary DESC
LIMIT 3;

Question: Retrieve the names of customers who have placed orders in the last 30 days.
Answer: Use: SELECT DISTINCT customer_name FROM customers JOIN orders ON
customers.customer_id = orders.customer_id WHERE order_date >= CURDATE() - INTERVAL
30 DAY;

Question: Calculate the total revenue for each product category.


Answer: Query: SELECT category, SUM(price * quantity) AS total_revenue FROM products
GROUP BY category;

Question: Find the employee with the second-highest salary.


Answer: Query: SELECT employee_name, salary FROM employees ORDER BY salary DESC
LIMIT 1 OFFSET 1;

MERN Stack Interview Questions:

Question: Explain the main components of the MERN stack.


Answer: The MERN stack consists of MongoDB (database), Express.js (backend framework),
React (frontend library), and Node.js (runtime environment).

Question: How does data flow between components in React?


Answer: In React, data flows unidirectionally from parent to child components through props.
Child components can update the parent's state via callback functions.

Question: What's the purpose of middleware in Express.js?


Answer: Middleware in Express.js provides a way to perform functions in the request-response
cycle. Common uses include handling authentication, logging, and error handling.

Question: Explain the concept of JSX in React.


Answer: JSX (JavaScript XML) is a syntax extension for React that allows you to write HTML-
like code within JavaScript. It helps create and manage React elements in a more readable
manner.

Question: How can you prevent a React component from rendering unnecessarily?
Answer: By using the shouldComponentUpdate lifecycle method or by utilizing the
React.memo() higher-order component to avoid unnecessary re-renders.

Question: Describe the purpose of Redux in a React application.


Answer: Redux is a state management library that helps manage the global state of a React
application. It maintains a single source of truth and enables predictable data flow.

ReactJS Interview Questions:

Question: Describe the differences between functional and class components in React.
Answer: Functional components are stateless and use functional syntax, while class
components can have state and lifecycle methods.

Question: How does React handle state management?


Answer: React uses state to manage component data that can change over time. State can be
updated using the setState() method, triggering re-rendering.

Question: Explain the concept of virtual DOM in React.


Answer: The virtual DOM is a lightweight copy of the actual DOM. React uses it to efficiently
update and render only the necessary changes, improving performance.

Question: What is a controlled component in React?


Answer: A controlled component is a React component where the form data is controlled by
React state. The component updates its state based on user input, and vice versa.

Question: Explain the concept of props drilling in React.


Answer: Props drilling occurs when you need to pass props from a parent component to
multiple nested child components. It can lead to complex and less maintainable code.

Question: How can you handle side effects in React functional components?
Answer: Use the useEffect() hook to manage side effects in functional components. It allows
you to perform actions like data fetching, subscriptions, and DOM manipulation.

You might also like