Forum Moderators: open

Message Too Old, No Replies

grouping and selecting

         

mattennant

7:27 am on Sep 21, 2008 (gmt 0)

10+ Year Member



i don't know if anyone can help me with a bit of logic

i have a table with the following columns

keywordrank_id (primary key)
article_id (the article reference primary key)
Keyword_id (1 = backpain) (2= fitness) etc --(just the number mind ya)
keyword_rank (this is either 0 or 1 depending on if a checkbox has been checked as related)

the table contains data for keywords that relate articles

all is well but if i am trying to add a new keyword to the table, so i'm trying to insert a new row for every article_id that does not have the option of checking this new keyword.

I have managed to single out the rows in the table that do have this keyword with the following statement

SELECT article_id FROM keyword_rank WHERE (keyword_id = 6) Group By article_id

this returns two rows 66 and 67

by changing (keyword_id = 6) to (keyword_id != 6)

i was hoping that this would select all the other rows excluding 66 and 67, but alas no,it selects all the rows. i was thinking i might need to use two statements,but have hit a bit of a mental block.

does that make any sense whatsoever to anyone out there?

ZydoSEO

1:27 pm on Sep 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your post is very hard to follow. But if the SELECT statement above returns the article_ids of the articles you do NOT want to insert rows for then simply use a NOT IN clause. I'm guessing you're doing an INSERT with SELECT and that keywordrank_id is an AUTO INCREMENT / AUTO GENERATED key, so the final statement would be similar to:

INSERT INTO mytable
SELECT article_id, SomeValueForKeywordID,SomeValueForKeywordRank
FROM mytable
WHERE article_id NOT IN (
SELECT article_id FROM keyword_rank WHERE (keyword_id = 6) Group By article_id
)

mattennant

10:07 am on Sep 24, 2008 (gmt 0)

10+ Year Member



Oh just found this, thanks for persevering with the convoluted explanation, and thanks for the response, makes perfect sense, and works a treat
thankyou