Closed (won't fix)
Project:
Views (for Drupal 7)
Version:
6.x-3.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
21 Oct 2009 at 22:26 UTC
Updated:
1 Jan 2011 at 04:59 UTC
I'm wanting to be able to build a view using a query as the base 'table', is this possible with Views 2.0 and how might I do it?
Comments
Comment #1
dawehnerYou want to have a query and manipulate the query with views? This is afaik not supportet, views is a query builder not a query alter :)
Comment #2
greenskin commentedI want to build a query on top of another query. Whether the base query is from Views or hardcoded, either way. Essentially I want to build a View from a 'table' that is actually a query. For example the Views query would look something like this: 'SELECT * FROM ({BASE_QUERY}) AS base' instead of 'SELECT * FROM base_table AS base'. {BASE_QUERY} would be the query string. Obviously my example is not exactly how Views constructs aliases or selections.
Comment #3
merlinofchaos commentedI don't know if you can do this. My guess is that you can't.
Comment #4
esmerel commentedMerlin doens't think it can be done, it probably can't.
Comment #5
greenskin commentedI have done it by simply specifying my SQL code as the base table name, but was wondering if there is a way that would be more elegant. I guess this is turning out to be more of a feature request than a support request. I know that Views SQL's can get rather massive, but I think it would be a great feature if a view could be built off of another view. Essentially another view would be the 'base table'.
All Views should have to do is recognize the 'base table' is a view rather than a database table, build that view's SQL and insert that as the FROM table. For example, SELECT * FROM ({VIEW_SQL}) AS view_base. The parent view would inherit the table relationships for the base view. If the base view used the base table of {node} then tables being added to the parent view would 'JOIN {node_revision} AS node_revision ON view_base.nid = node_revision.nid'.
I don't use PostgreSQL so I don't know if it is possible to do subqueries in it or not. That might be the biggest limitation in implementing this type of functionality.
I'll make this a request for the 3.x branch.
I have a project that I would like to have the control over my SQL code via Views, but they require subqueries otherwise I would have to make multiple calls to the database and load data I don't actually need.
Comment #6
esmerel commentedComment #7
bojanz commentedThat's a hack.
Make a contrib module that does it, and does it well, then we can return to the idea (and maybe merge it into Views).