Iam using a stored procedure where the @emp_number is the input parameter and I want to know how internally this both queries work and which gives more performance....
SELECT
emp_name,emp_number,emp_state,emp_address,emp_status
FROM
tbl_emp_info
WHERE
emp_id = (
select max(emp_id) from tbl_emp_info WHERE emp_number = @emp_number
and emp_status in ('Active')
)
Here I declare a variable and get the max emp_id first and then pass it to the main query..Which one gives better performance and how does that internally fire in SQL server
Delcare @max_emp_id INT
SET @max_emp_id = select max(emp_id) from tbl_emp_info WHERE emp_number = @emp_number
and emp_status in ('Active')
SELECT
emp_name,emp_number,emp_state,emp_address,emp_status
FROM tbl_emp_info
WHERE emp_id=@max_emp_id
SELECT
emp_name,emp_number,emp_state,emp_address,emp_status
FROM
tbl_emp_info
WHERE
emp_id = (
select max(emp_id) from tbl_emp_info WHERE emp_number = @emp_number
and emp_status in ('Active')
)
Here I declare a variable and get the max emp_id first and then pass it to the main query..Which one gives better performance and how does that internally fire in SQL server
Delcare @max_emp_id INT
SET @max_emp_id = select max(emp_id) from tbl_emp_info WHERE emp_number = @emp_number
and emp_status in ('Active')
SELECT
emp_name,emp_number,emp_state,emp_address,emp_status
FROM tbl_emp_info
WHERE emp_id=@max_emp_id