SQL SubQuery
這篇不是教學文,是因為我太少寫SQL and T-SQL
常常忘記sub Query的下法特地上來memo一下
不要笑我,我不是學SQL出身的只是略懂..^^
SELECT * FROM CAM_CATALOG_CATEGORY as T1
WHERE T1.CATEGORY_ID IN
(
SELECT CATEGORY_ID FROM CAM_CATALOG_CATEGORY_RELATION as T2
WHERE T2.CATEGORY_ID=T1.CATEGORY_ID
) AND IMAGE_ID <> ''
通常這樣做效能都不是很好因為動用兩次Query,切記切記
再加上可以過濾另外一張table 的參考
SELECT * FROM CAM_CATALOG_CATEGORY as T1
WHERE (T1.CATEGORY_ID IN ( SELECT CATEGORY_ID FROM CAM_CATALOG_CATEGORY_RELATION as T2 WHERE T2.CATEGORY_ID=T1.CATEGORY_ID ) and T1.CATEGORY_ID not IN (SELECT LINK_ID FROM EMAP_MAPLINK as T3 WHERE T3.MAP_ID=20 ))AND IMAGE_ID <> '' AND CATEGORY_ID <> 20
SELECT * FROM EMAP_MAPLINK as T3 WHERE T3.MAP_ID=20
標籤:
SQL
|
This entry was posted on 下午1:41
and is filed under
SQL
.
You can follow any responses to this entry through
the RSS 2.0 feed.
You can leave a response,
or trackback from your own site.
0 意見:
張貼留言