Posts

Showing posts from April, 2009

SQL - SELECT withi a SELECT

I was trying to re-write some of the stored procedures for one of my office project the other day to exclude certain unwanted entries. It was done in such a manner. SELECT * FROM [table_A] LEFT JOIN [table_B] ON [table_A].column_id = [table_B].column_id WHERE [table_A].column_c NOT IN ( SELECT [table_A].column_c FROM [table_A] WHERE [table_A].column_c LIKE '%something' OR [table_A].column_c LIKE '%somethingC' OR [table_A].column_c IN ('value_A', 'value_B', 'value_C') ) I tested it in the SQL 2005 Manager Console, and it works fine. I tried it out as well on the actual website, and it does work as well. However, it did a significant drawback that I was not able to notice. This statement will not return anything, or throwing an exception saying "Timeout operation" when it was trying to return a large number of rows. I can't figure out why it doesn't work