2 Dimensional MySQL Query?
Ok, so I'm planning on designing a table that contains comments for all articles on my site, my articles already have unique ID numbers; so what I want to do is 开发者_如何学Cassign unique IDs for comments and have that record also contain the ID of the article to which it belongs. Designing the table is cake, what I am wondering is if there is a way to request a record that matches two different specs (Article ID and Comment ID).
I use PHP by the way. And the articles are in a MySQL database.
Thanks!
Would you ever need to select a comment by its ID? Surely the only scenario would be selecting all the comments for an article and throwing them onto the page.
Either way, unless I'm misinterpreting the question, the SQL at least simply is:
select * from comment where id = 1 and article_id = 2;
As per my above statement, one would assume you'd only ever need to:
select * from comment where article_id = 2;
This is a simple AND condition on your WHERE clause:
SELECT ...
FROM comments
WHERE article_id = 123
AND comment_id = 456
SELECT ... WHERE articleId = foo AND commentId = bar
精彩评论