Answer the question
In order to leave comments, you need to log in
How to continue sampling?
Hello, tell me please, I need to select the news of those users whose number of comments > 1 As a result, I have 3 tables: comments, news, users
Structure of the users table:
-id
-login
-data
Structure of the news table:
-id
-user_id
-title
-text
The structure of the comments table:
-id
-user_id
-news_id
-text
And for example, the comments table is filled like this:
I make the following query:
SELECT comments.user_id
FROM comments
GROUP BY comments.user_id
HAVING COUNT(comments.user_id) > 1
Answer the question
In order to leave comments, you need to log in
Shake!
Joints are not as scary as they seem, the main thing here is practice.
SELECT
USERS.LOGIN
, NEWS.TITLE
, NEWS.TEXT
FROM
USERS
LEFT OUTER JOIN
COMMENTS
ON
USERS.ID = COMMENTS.USER_ID
RIGHT OUTER JOIN
NEWS
ON
USERS.ID = NEWS.USER_ID
GROUP BY
NEWS.TITLE
, NEWS.TEXT
, USERS.LOGIN
HAVING
(COUNT(COMMENTS.ID) > 1)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question