How can I see the clean query of a view? I created a test view. It displays data of a content type 'Anagrafiche (name for internal use: contatti)'. The view has the following fields (sorry for the interface language):




Contenuto: Immagine (Img)    it's an image field 
Contenuto: Nome (Name)       it's a text field
Contenuto: Cognome (Surname) it's a text field


I used the proposed code for the following question, to get a 'clean' query: link

But the output was not what was expected:

SELECT
  node.nid AS nid,
  node.created AS node_created,
  node.changed AS node_changed,
  users_node.name AS users_node_name,
  users_node.uid AS users_node_uid,
  'node' AS field_data_field_immagine_node_entity_type,
  'node' AS field_data_field_nome_node_entity_type,
  'node' AS field_data_field_cognome_node_entity_type
FROM  node AS node
LEFT JOIN users AS users_node
  ON node.uid = users_node.uid
LEFT JOIN field_data_field_cognome AS field_data_field_cognome
  ON node.nid = field_data_field_cognome.entity_id
  AND (field_data_field_cognome.entity_type = 'node'
  AND field_data_field_cognome.deleted = 0)
WHERE (( (node.status = 1)
  AND (node.type IN  ('contatti')) ))
ORDER BY
  field_data_field_cognome.field_cognome_value ASC
LIMIT 20 OFFSET 0


I do not have very clear how the correct output should be, but by looking at the query, I gather that this piece is not correct

  'node' AS field_data_field_immagine_node_entity_type,
  'node' AS field_data_field_nome_node_entity_type,
  'node' AS field_data_field_cognome_node_entity_type


I also tried alternatives like the 'Devel' module and different types of hooks, but I never got what I wanted

@mikeytown2 I ran the query inside phpmyadmin
this is the result:


but the last three columns should not be node | node | node, 
but something like thatimg | myName | mySurname
I gather that this piece is not correct


It’s absolutely correct - Views is just using the query results to pass through some meta data about the operation.

In this case your view joins three different fields, and the types of entity that the fields are related to are nodes. Views is just keeping track of the that fact for each field, so it can use a generic processor for the results.

If you don’t need to use those fields from the query, you can safely ignore them.