sql

Need help with Join Problem

Hi I have 2 tables Table 1 ID Status 1 D 2 F 3 D Table 2 SID ID Approve 1 1 N 2 1 Y 3 1 Y 4 2 Y 5 3 Y Result:- Should be Table 1 (ID, Status) 3, D 2,F Should not display 1 (As one of child rows have N in the Approve Column) I need a query to joins 2 tables on ID and finds records that don not hav...

all rows plus min / max values using a single stored procedure

I have a custom data source which pulls out data form a flat file. The flat file contains a timestamp , source and data. I can use sp_execute to execute a select query against the flat file. I'm currently using 2 stored procedures . - one which runs a select * from flat_file into a temp table - the other which does a select min/max...

OR query performance and strategies with Postgresql

In my application I have a table of application events that are used to generate a user-specific feed of application events. Because it is generated using an OR query, I'm concerned about performance of this heavily used query and am wondering if I'm approaching this wrong. In the application, users can follow both other users and group...

Help with SQL View involving SUM function

I would like to get the following data (and more) into a single view. SELECT Price FROM dbo.OrderItems WHERE OrderItemTypeId = 0 And SELECT SUM (Price) AS ShippingTotal FROM dbo.OrderItems WHERE OrderItemTypeId = 1 I can’t seem to figure out how to do this with my weak SQL skills. Anybody know how I could do this? ...

Get column names when you load from an access file

I load 10 tables from an ACCESS 2007 file database. IS their a way I can get the column names into the dataset or do I have to rename each column? I am using Visual Studio 2008 in VB.NET. I would like to reference the columns in the code by the name and not have to use an index I just went ahead and added the following code for eac...

Storing XML dataset in SQL Server 2000

I need to save the DataSet, results of a reporting app, to a table in SQL Server 2000. Do I save the datasets the same way I would store files in the DB, via Byte Array()? ...

mysql select query help -- ORDER BY

I'm trying to construct a select query where it will take all the columns of 4 tables and then order and display the results by the column 'name' (the same in all tables). I'm still learning the ropes of MySQL. I'm finding that because the columns share the name 'name', only the results from the last table are displayed. Is there a wa...

Looking for sql to find a list of people in a database who don't have a particular row without using not exists.

It's easy to find all the users ids who have trait.color = "green" but I need to find all the people who don't. The obvious way is a subselect for all the ids where not exists (select id where trait.color = "green') but I was trying to think if there's a way to do it without a subselect. Is there some trick I don't know about? sybase 12...

Dynamic Update Query in Oracle

I'm trying to create a standard UPDATE query for a table. However, if certain criteria are met, some columns should be included/excluded from the UPDATE statement. For example: UPDATE TBL_PROJECT SET REVISION_COUNT = V_REVISION_COUNT ,PRIMARY_BRANCH = IN_PRIMARY_BRANCH ,PROJECT_STATUS = IN_PROJECT_STATUS ... WHERE ...

sql range operator

Is there a SQL construct or a trick to do something like: SELECT i WHERE i BETWEEN 0 AND 10; ? My first idea is to create a temporary table such as: CREATE TABLE _range ( i INT PRIMARY KEY ); and fill it INSERT INTO _range VALUES 0; INSERT INTO _range VALUES 1; etc. Is there a better way? UPDATE: I use sqlite in this partic...

Linked Server with MS SQL crashing / stopping after 5 sec

Hey, I have been having a problem with my linked servers. I am using Microsoft Server 2003 and Microsoft SQL Server Management Studio 2005. I am linking to a MYSQL database through Microsoft studio since all of our other databases are controlled through MSMS. The problem is that for any query that last for more than 5 sec I get this ...

Getting Insert statement Error, I cant figure out whats wrong though.

I am trying to insert into a DB with has the following columns: ID (autonumber), BonderIdentifier (text), Username (text), Login (date), Logout (date). BonderIdentifier, Username, Login is the PK. Here is what I do: Public Function submitNewToDB(ByVal sessionData As BonderSession) As Boolean Dim cn As OleDbConnection Dim cmd...

SQL Search based on multiple values without Intersect

I am trying to search for items (members) that match 0 or more field values in a simple table. I have a solution using INTERSECT, but would like to know if there as a better/simpler solution. Simplfied Scenario: A user will select 0 to 3 fields as search criteria. For each chosen field, the user will select (combobox) a value. These...

PLSQL - How to retrieve values into a collection given an array of values?

I have a procedure that accepts an array of folder IDs and needs to return a list of document IDs. Folders are associated to documents in a one-to-many relationship--there are many documents for each folder. Specifically, there is a documents table which has a parent_folderid fk to the folders table. This is what I have: PROCEDURE get_...

Get script of SQL Server data

I'm looking for a way to do something analogous to the MySql dump from SQL Server. I need to be able to pick the tables and export the schema and the data (or I can export the schema via SQL Server Management Studio and export the data separately somehow). I need this data to be able to turn around and go back into SQL Server so it need...

Running SQL on a model that I got from a gem

So, I'm working on a project that uses the acts_as_taggable_on_steroids gem. I've installed it as a gem, and it works great and all. Here's where I'm running into problems though - I want to generate a list of the top 25 used tags, and the number of times they've been used across all taggable items. Well, as it happens, acts_as_taggable...

Concurrent access problem in mysql database

Hi i'm coding a python script that will create a number child processes that fetch and execute tasks from the database. The tasks are inserted on the database by a php website running on the same machine. What's the good (need this to be fast) way to select and update those tasks as "in progress" to avoid to be selected by multiple tim...

How do I convert this INNER JOIN query from SQL Server to MySQL?

I'm currently migrating a customers application from ColdFusion on Windows with SQL Server to ColdFusion on Linux with MySQL and I'm running into some issues recreating their views with regards to joins. Can anyone help me work out how the following should be converted. SELECT <columns> FROM assetType INNER JOIN assets INNER JOIN ...

Oracle LEADING hint -- why is this required?

Suddenly (but unfortunately I don't know when "suddenly" was; I know it ran fine at some point in the past) one of my queries started taking 7+ seconds instead of milliseconds to execute. I have 1 local table and 3 tables being accessed via a DB link. The 3 remote tables are joined together, and one of them is joined with my local tabl...

Most useful SQL meta-queries

I have a passion for meta-queries, by which I mean queries that answer questions about data rather than answering with data. Before I get a lot of justified criticism, I do realize that the approach of meta-queries is not ideal, as eloquently described here for example. Nevertheless, I believe they do have their place. (So much so that ...