1

I have a code in D6 which is as given below

In Drupal 6 for each content type we had seperate table like content_type_[content_name] --------------Drupal 6---------------------

    SELECT nid, field_id_value, field_oid_value,field_sts_value 
    FROM {content_type_bstatus} fsa INNER JOIN
    ( SELECT MAX(nid) as maxnid , field_oid_value  // subquery
      FROM {content_type_bstatus}
      GROUP BY field_oid_value
    ) fsb
    ON fsa.nid = fsb.maxnid
WHERE fsa.field_sts_value <> 'success' 

In Drupal D7 we have seperate table for each fields within the content type like
field_data_[field_name]
and content_type is included only in nodes table
So, I am trying to implement the above code in D7

In Drupal D7 what i have tried is as follows but could not the exact solution

------------------Drupal 7---------------------------------- For the subquery above I have implemented the code below

SELECT MAX( entity_id ) , field_oid_value
FROM  `field_data_field_oid` 
GROUP BY field_oid_value

How can I add the rest of code ..I have tried something which does not work
How can I write the code in d6 to d7 . I am using db_query in d6 and would use db_query or db_select but
HOW CAN I USE THE CONTENT TYPE FIELDS WHICH ARE HAVING SEPERATE TABLES in d7 database structure??

1
  • Can you be more specific about what exactly you are trying to achieve? It looks like from your 7x query that you are just trying to find the highest or MAX() entity_id value for a particular table. Is that correct?
    – schnippy
    Commented Aug 17, 2013 at 14:27

1 Answer 1

3

You should add a new view by the UI. Then, you can display the generated SQL query, by activating the sql display below the views UI:

admin/build/views/tools (D6)
admin/structure/views/settings (D7)

enter image description here

You'll see live, what the sql query is :

enter image description here

Copy/Paste the sql and rearrange it

3
  • How is this answer related to above question ? Where does the view arise in the picture?
    – harshal
    Commented Aug 21, 2013 at 8:11
  • more details with screenshots
    – pico34
    Commented Aug 21, 2013 at 8:35
  • You meant to say first one should create a view based on query in d6 and copy paste the code given ..good idea..
    – harshal
    Commented Aug 21, 2013 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.