| Author |
Topic |
|
Learning
Starting Member
4 Posts |
Posted - 2004-11-03 : 16:22:22
|
| Actually, it looked so simple.Two tables- Categories* cat_id* cat_name- Articles* article_id* article_title* cat_idI need to generate a result set where for each category I get only ONE article (the latest one)so:categories:1 cat12 cat23 cat3articles:1 test1 32 test2 33 test3 14 test4 35 test5 16 test6 1Would have to return:cat1 - test6cat3 - test4But ehm......HOW?????, I'm crunching like crazy, I just can't work it out :(THANKS! |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-11-03 : 16:34:14
|
select max(article_title) as article_title, cat_id from articlesgroup by cat_id if you need to select more columns do and inner join with this query to the article tagle.select t1.*from articles t1 inner join (upper select statament) t2 on t1.article_title = t2.article_title and t1.cat_id = t2.cat_idGo with the flow & have fun! Else fight the flow |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-11-03 : 16:35:37
|
| Which one should be returned? The one with the lowest article ID? the highest? Remember, computers are smart but they need to be given very specific instructions on exactly what you want them to do.- Jeff |
 |
|
|
Learning
Starting Member
4 Posts |
Posted - 2004-11-03 : 16:52:57
|
| Well, I'm trying to return the one with the highest ID.Gonna try some more here :)THNX! |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-11-03 : 16:57:25
|
| spirit has given you the answer ....- Jeff |
 |
|
|
Learning
Starting Member
4 Posts |
Posted - 2004-11-03 : 17:07:24
|
| :(, that just doesn't seem to work, putting the max on title though :(since my sample was just a fiction example |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2004-11-03 : 22:56:07
|
quote: Originally posted by Learning :(, that just doesn't seem to work, putting the max on title though :(since my sample was just a fiction example
how about providing the real ddl and some sample data? or was your problem solved already?--------------------keeping it simple... |
 |
|
|
Learning
Starting Member
4 Posts |
Posted - 2004-11-03 : 23:01:37
|
| Thanks!, actually forgot to post my solution to it, it seems to work, thank you all!SELECT TOP 100 PERCENT t.article_id, dbo.adw_article_category.article_category_name, t.article_article_category_id, t.article_titleFROM dbo.adw_article t INNER JOIN dbo.adw_article_category ON t.article_article_category_id = dbo.adw_article_category.article_category_idWHERE (t.article_id IN (SELECT MAX(article_id) AS article_id FROM dbo.adw_article GROUP BY article_article_category_id)) AND (t.article_approved = 1)ORDER BY t.article_id DESC |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-11-04 : 04:14:02
|
a join will be faster....Go with the flow & have fun! Else fight the flow |
 |
|
|
|