sql - Do subselects do an implicit join? -


I have a SQL query that seems to work but why I really do not understand That's why I greatly appreciate if someone is helping someone to explain what is happening:

Question Returns: All organizations who do not have any comments that have not been created by the consultant Who had set up the organization record. Organizations \ "where \" organization \ ". \" Id \ "(select \" comments \ ". \" Commentable_id \ comments \ "where \" comment \ ". \" Commentable_type \ "= 'Organization' and ( comments.author_id! = Organizas.consultant_id) \ "comments \" command \ "made_at \" ASC)

it is worth it.

I understand why the part is not (comments.author_id! = Organization.consultant_id) is working!? I do not understand how the postgres know this too What is the "organization" within that organization? It has not been defined here.

If it was written as a join, where I was involved in the comments in organizations, then I fully understand how you can do something like this. but in this case it is a subgenre. it shows how how comments and where to map the organizations of the table and those outside the (comments.author_id! = Organizasations.consultant_id)

This sub-row is in the line, so it can see all the columns in that row. You may select from this

  organizations. * To get better performance from such organizations where no one selected observations (where commentable_type = 'organization' and author_id! = Organizations.consultant_id)  

Note that commentable_type is not required to qualify because more than any other code outside the sub code is comment priority. And if there is no consultant_id column in comment , it would be possible to exclude its eligibility, although not recommended for better clarity.

Order in your query does not buy anything, only added value.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -