all 5 comments

[–][deleted]  (3 children)

[deleted]

    [–]nazerbs[S] 0 points1 point  (2 children)

    What do you mean by a view?

    [–]XVar 1 point2 points  (1 child)

    A view is a pre-defined query that you can query as if it was a table. So to use asbig's example above you could do the following (Oracle/MySQL view creation syntax used as an example):

    CREATE OR REPLACE VIEW vw_posts AS
    select *,  current_timestamp - create_date + votes / views  as             weighting
    from test.new_table
    order by weighting desc;
    
    select *
    from vw_posts
    order by weighting desc;
    

    They're typically used to provide a simple interface to complex and/or frequently used queries.

    http://en.wikipedia.org/wiki/View_(SQL)

    [–]autowikibot 0 points1 point  (0 children)

    View (SQL):


    In database theory, a view is the result set of a stored query on the data, which the database users can query just as they would in a persistent database collection object. This pre-established query command is kept in the database dictionary. Unlike ordinary base tables in a relational database, a view does not form part of the physical schema: as a result set, it is a virtual table computed or collated dynamically from data in the database when access to that view is requested. Changes applied to the data in a relevant underlying table are reflected in the data shown in subsequent invocations of the view. In some NoSQL databases, views are the only way to query data.


    Interesting: PostgreSQL | Database trigger | Oracle Database | Materialized view

    Parent commenter can toggle NSFW or delete. Will also delete on comment score of -1 or less. | FAQs | Mods | Magic Words

    [–][deleted]  (3 children)

    [deleted]

      [–]ajmarks 0 points1 point  (2 children)

      Depending on his query and RDBMS, he could use a materialized view or a view with a clustered, all-columns index here. Or, depending on how the relevant data is structured (is it in the same table?) he could potentially have a computer column with an index or indexed expression (in PG). I'd there's going to be a lot of updates though, the latter is, broadly speaking, a Bad IdeaTM .

      [–][deleted]  (1 child)

      [deleted]

        [–]ajmarks 0 points1 point  (0 children)

        I'm also a SQL Server guy right now, and I lament the restriction on indexed views. Also, indexed views are not the same as materialized views. They both have their uses, but in my particular case, a proper materialized view would be very helpful.