Jump to content

Show threads where there is no messages inside


Recommended Posts

I want to select all threads even though the count(Messages.TitleID) is zero.. Is like when u start a new thread with no messages currently posted. How can i modify the codes to do it?SELECT Thread.ThreadTitle, COUNT(Messages.TitleID) AS NoOfMessage, Thread.ThreadID FROM (Thread INNER JOIN Messages ON Thread.ThreadID = Messages.ThreadID) GROUP BY Thread.ThreadTitle, Thread.ThreadID

Link to post
Share on other sites

You need to use a left outer join instead of an inner join. An inner join will only give you records that exist in both tables. If you do this:A left outer join BIt will give you all the rows in A (because it's on the left), and only the rows in B that match. If you do this:A right outer join BIt will give you all the rows in B (because it's on the right) and only the rows in A that match.

Link to post
Share on other sites
You need to use a left outer join instead of an inner join. An inner join will only give you records that exist in both tables. If you do this:A left outer join BIt will give you all the rows in A (because it's on the left), and only the rows in B that match. If you do this:A right outer join BIt will give you all the rows in B (because it's on the right) and only the rows in A that match.
Thanks for your help.. ITs done.. :) I got another problemI need to delete the thread(parent class) which it will auto delete all messages(child class).How to modify the delete statement?
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...