3 Replies - 1099 Views - Last Post: 02 December 2009 - 06:16 PM

#1 Addiction2Code  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 19-December 06

MySQL Query, Selecting information from multiple tables...

Posted 02 December 2009 - 03:31 PM

Alright, so I am working on a website that contains articles. I want to select all articles that are associated with the category Blog. There is a table called "ArticleKeys" that has a bunch of article ids (article_id) and a bunch of category ids (category_id) in it, the category_id's are the ids in the table Categories which each has a field "id" and "name". I would like to select only the articles from "Articles" where the article is associated with category name Blog.

Sorry I don't have any code to show.

Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: MySQL Query, Selecting information from multiple tables...

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: MySQL Query, Selecting information from multiple tables...

Posted 02 December 2009 - 03:41 PM

Moved to Databases.
Was This Post Helpful? 0
  • +
  • -

#3 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 463
  • View blog
  • Posts: 820
  • Joined: 17-June 08

Re: MySQL Query, Selecting information from multiple tables...

Posted 02 December 2009 - 04:25 PM

Sounds like a fairly standard join to me. Something like this:
SELECT art.* FROM 
Articles AS art 
JOIN ArticleKeys AS keys ON art.id = keys.article_id
JOIN Categories AS cat ON cat.id = keys.category_id
WHERE cat.name = 'Blog';


Was This Post Helpful? 0
  • +
  • -

#4 Addiction2Code  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 19-December 06

Re: MySQL Query, Selecting information from multiple tables...

Posted 02 December 2009 - 06:16 PM

Thank you, that was exactly what I was looking for, however; what if I wanted to select everything that was NOT tagged blog, looking at this code I realise why != 'Blog' will not work. I am very bad with MySQL in this manner.

This post has been edited by Addiction2Code: 02 December 2009 - 07:20 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1