Posted by Alexander Kuznetsov on 08/21/06 19:35
Ted wrote:
> I constructed the following SQL statement by studying the example on
> page 392 in Itzik Ben Gan et al.'s "Inside Microsoft SQL Server 2005:
> T-SQL Querying"
>
> SELECT s_supplier_code, s_supplier_name FROM suppliers AS S1
> WHERE s_supplier_code =
> (
> SELECT TOP(1) * FROM suppliers AS S2
> WHERE S2.s_supplier_code = S1.s_supplier_code
> ORDER BY s_supplier_name
> )
> ;
>
Ted,
The example in Listing 7-1 is different from your query, and the
example works (and it makes perfect sense to me). I am not sure I
understand what you were trying to accomplish. Note that:
1. Listing 7-1 uses SELECT TOP(1) OrderId, as opposed to your top(1) *
2. Listing 7-1 uses different columns to filter the result set
(OrderId) and to correlate the subquery (EmployeeId). Using one and the
same solumn s_supplier_code in both cases makes little sense to me.
Good luck!
[Back to original message]
|