[RESOLVED] Are these two simple queries identical?
Both in terms of results produced and performance?
Code:
SELECT sab_stuc AS StudentID
, sab_seq2 AS SequenceNo
, (SELECT raa_name FROM srs_raa WHERE raa_code=sab_raac) AS RecordReason
, sab_begd AS [Date]
, sab_udf1 AS AMPM
FROM srs_sab
SELECT sab_stuc AS StudentID
, sab_seq2 AS SequenceNo
, srs_raa.raa_name AS RecordReason
, sab_begd AS [Date]
, sab_udf1 AS AMPM
FROM srs_sab
INNER JOIN srs_raa ON raa_code=sab_raac
Re: Are these two simple queries identical?
The results should be identical, as long as every record in srs_sab has a matching record in srs_raa. If they don't, the first query will probably (depending on the database system) return the srs_sab records with Null for RecordReason, but the second query wont return those records at all.
The performance is not so easy to determine, even when the results are identical... depending on the query parser in the database system, they might be exactly the same, but they might differ quite a bit (and if so, there are too many factors to predict which would be faster).
Re: Are these two simple queries identical?
Thanks, in terms of point one there should always be values to join on so am happy that the results will be the same.
In terms of performance, using SQL Server 2012 against 100k records in the main table both queries run in between 1-2 seconds. So unless as the records grow and the time becomes slow I may revisit and look at the plans.
I just wanted to be sure there wasnt an obvious difference as a new developer used the first one which is against my norm.