My aim is to write the last modified date (lastmod
) of my approved articles for my sitemap.xml
file. There are 2 possibilities for this data.
- If article has no approved comment, then lastmod is the approval date of the article.
- If article has at least 1 approved comment, then lastmod is the approval date of the last approved comment of related article.
after asking php unsuccessful while loop within prepared statements question and reading answers, I decided
- not to use loop within prepared for this case
- add
col_article_id
column to my comments table which shows the related article's id in article table - and try to solve my case with a smarter mySQL query
I have 2 tables:
- articles
- comments (
comments.col_article_id
links the comment to the related article)
After I tried query below,
select tb_articles.col_approvaldate, tb_comments.col_approvaldate
from tb_articles, tb_comments
where tb_articles.col_status ='approved' AND tb_comments.col_status ='approved' AND tb_articles.col_id=tb_comments.col_article_id
my problems are:
1 - I need someway as if it was allowed in mysql syntax that select max( tb_articles.col_approvaldate, tb_comments.col_approvaldate)
2 - If I have n approved articles without any approved comment and m approved articles with approved comment(s), then I should have n+m result rows with 1 column at each row. But currently, I have m rows with 2 columns at each row.
So I'm aware that I'm terribly on wrong way.
I also searched "mysql newest row per group" keywords. But this the point I could arrived after all.
this is my 1st join
experience. can you please correct me? best regards