sql-view

How to CREATE a 'VIEW(SQL)' in CodeIgniter and SELECT data from it?

≡放荡痞女 提交于 2019-12-08 01:48:33
问题 I have a query that needs to check whether the record is still active before it includes it in the query. Now my problem is that the record status of that record is in another database and WE all know that we cant join tables from different databases. What I want to do is to create a view from the other database and I'll just join that view to my query. The problem is HOW can I create a view and select data from it in CodeIgniter? Thanks in advance. By the way, Im not the one who designed the

mysql create view only if it doesn't already exist

喜你入骨 提交于 2019-12-07 01:52:02
问题 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. 回答1: You're going to kick yourself: CREATE OR REPLACE VIEW ... Details here. ;-) 回答2: CREATE OR REPLACE VIEW <view name> AS <your select expression goes here> 来源: https://stackoverflow.com/questions/2245847/mysql-create-view-only-if-it-doesnt-already-exist

How to add ROW_NUMBER() in a view?

让人想犯罪 __ 提交于 2019-12-07 01:25:40
问题 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 lineView AS SELECT 'name' AS name_dispatcher, the_geom FROM line1 UNION SELECT 'name' AS name_dispatcher, the_geom FROM line2 UNION SELECT 'name' AS name_dispatcher, the_geom FROM line3 How to create the num column in the view? UPDATE I found a

How can I use SQL Server Table Views as Rails Models (Read Only)?

南笙酒味 提交于 2019-12-06 14:22:22
I'm using SQL Server as my database for my Rails project. I'm trying to create some models to use for a 3rd party database and only want to read from this database. So I made a view of the table I wanted to create an object for and then I wanted to point my active record model to it. However, in rails console I don't get back expected results. The only example that gives back some correct information is when I do a count on the object as shown in Example 3 below. I'm using the following gems to connect to my SQL Server: gem 'tiny_tds' gem 'activerecord-sqlserver-adapter' Also I have installed

mysql create view only if it doesn't already exist

被刻印的时光 ゝ 提交于 2019-12-05 06:00:56
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. You're going to kick yourself: CREATE OR REPLACE VIEW ... Details here. ;-) CREATE OR REPLACE VIEW <view name> AS <your select expression goes here> 来源: https://stackoverflow.com/questions/2245847/mysql-create-view-only-if-it-doesnt-already-exist

Performing string concatenation from rows of data in a TSQL view (pivot?)

帅比萌擦擦* 提交于 2019-12-04 22:31:11
问题 I'd like to create a view in SQL Server that combines several pieces of database metadata. One piece of metadata I want lives in the sys.syscomments table - the relevent columns are as follows: id colid text ---- ------ ------------- 1001 1 A comment. 1002 1 This is a lo 1002 2 ng comment. 1003 1 This is an e 1003 2 ven longer c 1003 3 omment! As you can see the data in the "text" column is split into multiple rows if it passes the maximum length (8000 bytes/4000 characters in SQL Server, 12

Create view with primary key?

冷暖自知 提交于 2019-12-04 22:27:07
I create a view with following codes SELECT CONVERT(NVARCHAR, YEAR(okuma_tarihi)) + 'T1' AS sno, YEAR(okuma_tarihi) AS Yillar, SUM(toplam_kullanim_T1) AS TotalUsageValue, 'T1' AS UsageType FROM TblSayacOkumalari GROUP BY CONVERT(NVARCHAR, YEAR(okuma_tarihi)) + 'T1', YEAR(okuma_tarihi) UNION ALL SELECT CONVERT(NVARCHAR, YEAR(okuma_tarihi)) + 'T2' AS sno, YEAR(okuma_tarihi) AS Yillar, SUM(toplam_kullanim_T2) AS TotalUsageValue, 'T2' AS UsageType FROM TblSayacOkumalari GROUP BY CONVERT(NVARCHAR, YEAR(okuma_tarihi)) + 'T1', YEAR(okuma_tarihi) UNION ALL SELECT CONVERT(NVARCHAR, YEAR(okuma_tarihi))

Data from two tables into one view

泪湿孤枕 提交于 2019-12-04 17:33:51
问题 Is it possible to grab data from two tables (that have the same fields) into one view. Basically, so the view sees the data as if it was one table. 回答1: Yes, using a UNION - CREATE VIEW vw_combined AS SELECT * FROM TABLE1 UNION ALL SELECT * FROM TABLE2 ...requires that there be the same number of columns, and the data types match at each position. ..preferrably, using a JOIN: CREATE VIEW vw_combined AS SELECT * FROM TABLE1 t1 JOIN TABLE2 t2 ON t2.col = t1.col But I want to warn against

Select Columns of a View

家住魔仙堡 提交于 2019-12-04 16:14:41
问题 I'm attempting to select the column names of a view in a similar way as selecting from information_schema.columns . I can't seem to find a way to do this. Has anyone else done this before or know if it is even possible? 回答1: information_schema.columns.Table_name (at least under Sql Server 2000) includes views, so just use SELECT * FROM information_schema.columns WHERE table_name = 'VIEW_NAME' 回答2: Try this: SELECT * FROM sys.views This gives you the views as such - if you need the columns,

Wordpress users and usermeta - joining multiple rows in one table to one row in another table

梦想的初衷 提交于 2019-12-04 07:48:48
问题 I want to create a view from both the wp_users and wp_usermeta tables so that I can query rows in the view from an external application. Basic auth details are stored in wp_users (e.g. username, password, email, id) and other fields are stored in key/value pairs in the wp_usermeta table. the wp_users table is structured like this: id | login | password | email ----------------------------- 1 | bsmith| abc123 | b@foo.com 2 | jjones| def456 | k@bah.com the wp_usermeta table is structured like