[thelist] sql/table design question
.jeff
jeff at members.evolt.org
Wed Feb 19 02:55:01 CST 2003
joshua,
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Joshua Olson
>
> SELECT RelatedBook = CASE
> WHEN Book1 = 1234 THEN Book2
> ELSE Book1 END
> FROM table
> WHERE Book1 = 1234
> OR Book2 = 1234
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
what about this instead?
SELECT DISTINCT relatedBook
FROM (SELECT book2 AS relatedBook
FROM table
WHERE book1 = 1234
UNION ALL
SELECT book1 AS relatedBook
FROM table
WHERE book2 = 1234)
ORDER BY relatedBook
this has the advantage of not resulting in duplicate relatedBook records,
should the data make that possible, which yours does not address (without
adding DISTINCT in front of RelatedBook).
however, now that i compare them in query analyzer i'm not sure this is an
improvement. so, anyone else with ideas?
.jeff
http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/
More information about the thelist
mailing list