Questions tagged [sql-view]

A database view is a stored query. Its output automatically updates as underlying table data changes.

A database view does not store data as tables (temporary or otherwise) do; rather, it is a saved query that can be recalled and reused. Its output automatically updates as underlying table data changes.

Reference

990 questions
9
votes
1 answer

Change PostgreSQL columns used in views

I would like PostegreSQL to relax a bit. Every time I want to change a column used in a view, it seems I have to drop the view, change the field and then recreate the view. Can I waive the extra protection and just tell PostgreSQL to let me change…
Larsenal
  • 49,878
  • 43
  • 152
  • 220
9
votes
2 answers

Using COALESCE in SQL view

I need to create a view from several tables. One of the columns in the view will have to be composed out of a number of rows from one of the table as a string with comma-separated values. Here is a simplified example of what I want to…
kateroh
  • 4,382
  • 6
  • 43
  • 62
9
votes
2 answers

SQL server view return different results in Entity Framework

I have a sql view in SQl server: SELECT dbo.job.idJob, SUM(dbo.tracking.iQty) AS TotalOrdered, dbo.tracking.idProduct FROM dbo.tracking INNER JOIN dbo.job ON dbo.tracking.idJob = dbo.job.idJob GROUP BY…
J King
  • 4,108
  • 10
  • 53
  • 103
8
votes
4 answers

SQL Server view: how to add missing rows using interpolation

Running into a problem. I have a table defined to hold the values of the daily treasury yield curve. It's a pretty simple table used for historical lookup of values. There are notibly some gaps in the table on year 4, 6, 8, 9, 11-19 and 21-29. The…
Christopher Klein
  • 2,773
  • 4
  • 39
  • 61
8
votes
1 answer

MS Access: WHERE-EXISTS-clause not working on views?

Prerequisites: In MS Access 2010 create the following tables: CREATE TABLE ATBL(ID INT); INSERT INTO ATBL(ID) VALUES (1); INSERT INTO ATBL(ID) VALUES (2); INSERT INTO ATBL(ID) VALUES (3); CREATE TABLE BTBL(ID INT); INSERT INTO BTBL(ID) VALUES…
8
votes
3 answers

View based on SELECT with 'WITH' clause

I've select with 'WITH' clause: with alias1 as (select...), alias2 as (select ... from alias1), alias3 as (select col1, col2 ... from alias2) select col1,col2 from alias3 I tryied to create view using: create view ex_view as ( with alias1 as…
R. Nec
  • 315
  • 2
  • 5
  • 10
8
votes
2 answers

creating django model for existing database/sql view?

I have inserted a definition for a view in $template_dir/sql/$someTableName.sql file. (create or replace view) so every time I run syncdb, the db views are created. Can I create in models.py a python class which accesses that view? Is it better…
Alexander Bird
  • 38,679
  • 42
  • 124
  • 159
8
votes
2 answers

SQL Server add computed column in VIEW with conditions

Here is my situation: In my table i two fields: - Price (decimal (15,4) - TaxId (int) TaxId value is not stored anywhere but there are only two values (actualy 3). - 1 (8.5%) - 2 (20%) - NULL (no tax) Now i need calculated column in my view that…
no9
  • 6,424
  • 25
  • 76
  • 115
7
votes
2 answers

How can I see the Original MySQL used to create a view in phpMyAdmin or other program?

How can I see the original MySQL used to create a view in phpMyAdmin or other program? I am using phpMyAdmin version 3.3.9. This post tells how to see the SQL used to create a view but its not the original SQL used. How can I edit a view using…
zechdc
  • 3,374
  • 9
  • 40
  • 52
7
votes
2 answers

PostgreSQL Views: Referencing one calculated field in another calculated field

I have the same question as #1895500, but with PostgreSQL not MySQL. How can I define a view that has a calculated field, for example: (mytable.col1 * 2) AS times_two ... and create another calculated field that's based on the first one: …
John
  • 267
  • 2
  • 4
  • 9
7
votes
2 answers

Combine results of two unrelated queries into single view

Is it possible to combine the results of two separate (unrelated) sql queries into a single view. I am trying to total some figures for users and count the views for videos this month to display on a dashboard. i.e., select count(*) from video where…
M Azam
  • 518
  • 1
  • 7
  • 28
7
votes
2 answers

mysql create view only if it doesn't already exist

How do I create a view only if it doesn't exist. If it does exist, I want to drop the view and redefine it. I also want no warnings or errors.
Alexander Bird
  • 38,679
  • 42
  • 124
  • 159
7
votes
3 answers

Ignore create/change of model for a SQL View using Entity Framework

If I create a SQL view and write a model to represent that view I will still want it to map up to be able to read data from the SQL view. The Add-Migration code will see this as a new table because entity framework (version 6) doesn't understand…
Csharpfunbag
  • 395
  • 3
  • 19
7
votes
5 answers

What does 'vw' mean in this SQL statement?

What does vw mean in front of TournamentDetails? SELECT * FROM vwTournamentDetails WHERE firstname='@firstName' AND lastname='@lastName' AND --etc Where is the table TournamentDetails coming from? We have no table named…
Christopher
  • 169
  • 1
  • 2
  • 10
7
votes
1 answer

How to add ROW_NUMBER() in a view?

In PostgreSQL 8.4 I want to create a view from 3 tables with id. So I want to have this structure in my view: num serial, name_dispatcher character varying(250) the_geom geometry I can select name_dispatcher and the_geom from tables: CREATE VIEW…
Kliver Max
  • 5,107
  • 22
  • 95
  • 148
1 2
3
65 66