469,326 Members | 1,359 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

Select items with same catehory as given item

Hey

I have two tables:

TABLE_ARTICLE
article_id******article_name article_content

TABLE_ARTICLE_SECTION
article_id *section_id
Given an article_id, how do I select all articles from
TABLE_ARTICLE that have the same section_id as that of a given
article_id.

Something like this but for mysql:
SELECT table_article.* FROM table_article,table_section WHERE
table_section.section_id IN (SELECT section_id FROM table_section
WHERE article_id="something")

Thanks
Joshua
Jul 19 '05 #1
2 1373
BDR
select * from TABLE_ARTICLE
LEFT JOIN TABLE_ARTICLE_SECTION ON
(TABLE_ARTICLE.article_id=TABLE_ARTICLE_SECTION.ar ticle_id)
WHERE TABLE_ARTICLE.article_id='something'

Check mysql.com for other variants on this same theme... "table JOIN(s)"
http://www.mysql.com/doc/en/JOIN.html

Jadow wrote:
Hey

I have two tables:

TABLE_ARTICLE
article_id article_name article_content

TABLE_ARTICLE_SECTION
article_id section_id
Given an article_id, how do I select all articles from
TABLE_ARTICLE that have the same section_id as that of a given
article_id.

Something like this but for mysql:
SELECT table_article.* FROM table_article,table_section WHERE
table_section.section_id IN (SELECT section_id FROM table_section
WHERE article_id="something")

Thanks
Joshua


Jul 19 '05 #2
BDR
select * from TABLE_ARTICLE
LEFT JOIN TABLE_ARTICLE_SECTION ON
(TABLE_ARTICLE.article_id=TABLE_ARTICLE_SECTION.ar ticle_id)
WHERE TABLE_ARTICLE.article_id='something'

Check mysql.com for other variants on this same theme... "table JOIN(s)"
http://www.mysql.com/doc/en/JOIN.html

Jadow wrote:
Hey

I have two tables:

TABLE_ARTICLE
article_id article_name article_content

TABLE_ARTICLE_SECTION
article_id section_id
Given an article_id, how do I select all articles from
TABLE_ARTICLE that have the same section_id as that of a given
article_id.

Something like this but for mysql:
SELECT table_article.* FROM table_article,table_section WHERE
table_section.section_id IN (SELECT section_id FROM table_section
WHERE article_id="something")

Thanks
Joshua


Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Charlotte Henkle | last post: by
4 posts views Thread by headware | last post: by
6 posts views Thread by Ben Hallert | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.