sql

SQL to combine 2 tables

I have 2 separate queries that returns to me the following tables: =========================== Id f_name l_name =========================== 15 Little Timmy 16 John Doe 17 Baby Jessica --------------------------- =========================== Id item_name item_price =========================== 15 Camera...

Updating a table with multiple values from a select statement where the date matches

I'm having a problem updating a table and im sure its pretty straight forward but im going round and round in circles here. Table 'table1' data I want to update is formatted as follows: [Month] Figure ---------------------------------- 2010-05-01 00:00:00.000 1.0000 2010-06-01 00:00:00.000 1.0000 2010-07-01 00:00:00....

Indexed Views Don't appear to be equivalent to Oracle Materialized

Hi All, It has been quite a while since I used SQL Server and had been primarily working on Oracle DBs. I had grown accustomed to building materialized views off of my OLTP tables to speed up performance. I was excited to find information around what appeared to be the SQL Server equivalent of a Mat view...however, when I started read...

Need help Updating data from two database and two tables.

I am trying to update data from another table/databases Database 1 = Client, Table 1 = Customer$ Account Number, Zip and Phone Database 2 = Site10 and Insurance Need to update Site 10 with Zip from Database 1 which is the client Need Help???? ...

SQL table design advice

Hey i want to create a list like this. The pic below isnt my list just an example of what i want to create. My category table is currently just: category( id int, title varchar(20) ) Should i just keep everything in one table or add a section table to deal with each category section? ...

How to query for rows that have highest column value among rows that have same value for one of the columns

I have UserScores Table with data like this: Id userId Score 1 1 10 2 2 5 3 1 5 I would like to have a query or SQL block that can give me the following output Id userId Score 3 1 5 2 2 5 That is, I would like to pick rows that are unique by 'user id' that belong...

Is a Primary Key necessary in SQL Server?

This may be a pretty naive and stupid question, but I'm going to ask it anyway I have a table with several fields, none of which are unique, and a primary key, which obviously is. This table is accessed via the non-unique fields regularly, but no user SP or process access data via the primary key. Is the primary key necessary then? Is...

Deleting table data from tablespace in Oracle

I tried to delete the data from tablespace using the command DROP USER xyz CASCADE; I found that user was dropped but size of my tablespace did not decreased. Is my data fom the tablespace have been deleted? If yes, how can I confirm that? And why was the space not deallocated? ...

Finding keys in a db table that arent in a list

On sybase. I've got a load of primary keys If I do: select key from table where key in (...list of about 2000 keys...) I get about 1700 results. Whats the easiest way to get a list of the ~300 entries in my list that arent present? It seems to be something that should be easy, but I cant work it out... EDIT: Seems an example may be ...

How to modify an NHibernate query to behave like simple SQL?

I'm trying to modify the following code so that it will return a Dictionary<int,int> where the keys correspond to groupId and the values correspond to the total companies in the group, instead of a List<Company> companies = _session.CreateCriteria<Company>() .Add<Company>(x => x.CompanyGroupInfo.Id == groupId) .List<Company>(); ...

SQL-Query: EXISTS in Subtable

I have two tables tabData and tabDataDetail. I want all idData(PK) from Parent-Table(tabData) that have only rows in Child-Table(tabDataDetail, FK is fiData) with: fiActionCode=11 alone or fiactionCode=11 and fiActionCode=34 Any other combination is invalid. How to get them? What i've tried without success(slow and gives me also r...

SQL Calculated Field

I'm creating a view as such: CREATE VIEW all AS SELECT m.id, m.title, m.description, m.date, m.views, r.rating, r.id FROM riv_montage m, riv_ratings r But I'd like to create a calculated field on each row that does something like: r.rating/COUNT(r.id) Is there any way to do this? ...

Generating meaningful performance estimates for a dataset + query?

Hi, I'm writing a web app which is using a mysql database. I want to show running time for a particular query, but I want it to be useful for other developers trying to do the same thing. The point is to give other developers an idea as to the cost of doing this query if they try the same web app pattern. What is a good way to do this?...

SQL Server Management Studio

Is it possible to install Management Studio by itself, and if so, is there a separate download/install exe for it? ...

How can I see the contents of an Oracle index?

Is it possible to have a look at what is there inside an index using SQL*Plus? If I have a table like this: Table A ------------------------ rowid | id name 123 | 1 A 124 | 4 G 125 | 2 R 126 | 3 P where id is the primary key, I expect the index to be something like this index on A.id ------------- id ...

High level Postgres run down of INSERT/UPDATE speed?

I know that when I UPDATE a row in Pg, that row gets rewritten and the old row gets deactivated when the new row gets activated. I know this is due to how the MVCC layer is implemented. What the advantages then of UPDATE over DELETE ... INSERT? Is there anything else to be said about the relationship of UPDATE and DELETE in Postgresql? ...

SQL - "IF" in Where Clause

I'm trying to write a stored procedure that will have 6 bit value flags as parameters and a couple of other values. The pseudo sql I want to write is something like: SELECT * FROM theTable WHERE IF @flagA = 1 THEN theTable.A = 1 IF @flagB = 1 THEN theTable.B = 1 IF @flagC = 1 THEN theTable.CValue = @cValue ...

Column creation and use

Hi, I am fairly new to SQL, so not sure if this is just a SQL compiler thing or not. When I have used SQL before it's been through JAVA or PHP, never just straight SQL. I am using SQL Server 2005 and attempting to add a column to my table, and then populate it. Here is what I have now: ALTER TABLE House DROP COLUMN CustomerType ALTE...

SQL transform semi-colon list into relationship table

I currently have a code table containing a list of types (Type_ID, Description), but they are saved in another table as ID;;ID;;ID...etc I am looking for a script that will take those ID's and place them in a relationship table corresponding to there Type ID For example in table A the Type_ID entries could look like: 1;;2;;4 1 ...

Combine php variable and SELECT variables into one SQL Insert query

Hi, I've the following query: INSERT INTO table ( memberid, field1, field2, field3 ) VALUE...