To fetch employees based on a given department name using SQL, you can use a SQL query with a JOIN clause and a WHERE condition to filter by the department name. Assuming you have two tables, Employee and Department , with appropriate columns. Department: id name 1 HR 2 Java Employee: id name department_id 101 Gangu 1 103 Naidu 2 SQL query to achieve this: sql SELECT e.name AS employee_name FROM Employee e JOIN Department d ON e.departmentId = d.id WHERE d.name = 'Java' ; In this SQL query: We select the name of the employees from the Employee table and alias it as employee_name . We perform an INNER JOIN between the Employee and Department tables based on the departmentId column in the Employee table and the id column in the Department table. This links employees to their respective departments. We use a WHERE condition to filter the results. In this case, we filter employees whose department's name matches 'Java'. You can replace 'Java...
To find the second-highest salary from a list of employees using Java 8 streams, you can follow these steps: Create a list of employees with their salaries. Use Java 8 streams to sort the employees by salary in descending order. Skip the first element (which is the employee with the highest salary). Get the first element of the remaining stream (which is the employee with the second-highest salary). Example code: java import java.util.ArrayList; import java.util.List; class Employee { private String name; private double salary; public Employee (String name, double salary) { this .name = name; this .salary = salary; } public double getSalary () { return salary; } } public class SecondHighestSalary { public static void main (String[] args) { List<Employee> employees = new ArrayList <>(); employees.add( new Employee ( "John" , 60000.0 )); employees.add( new Employe...