sql

Generic database logging system: Storing a reference to another database.table.column

My question is, how can I link a reference stored in the Log table to a piece of data in another database? We're building a system (Called Fusion) that will perform certain key tasks for all our other systems, one of these is a logging. The idea is that any other system will be able to use Fusion to log specific operation. CREATE TAB...

How does BULK INSERT work internally ?

Hi , Could someone please explain how does BULK INSERT internally work and why is it much faster than the normal INSERT operations ? Regards, Shishir. ...

Mysql NOT IN operator performance problems for large result sets?

I have the following two queries: select count(*) from segmentation_cycle_recipients scr , segmentation_instance si where si.access_code=scr.access_code and si.segment_id is NOT NULL; Returns 13429 rows in 0.2 secs 2) select count(*) from segmentation_cycle_recipients scr , segmentation...

Localizing data in SQL Server 2008 tables and sorting

I need to localize data in tables in a SQL Server 2008 database. Each language will need its own sort order when selecting records. I was told in another thread that creating separate tables for each language would make it nearly impossible to create the select statement in a Stored Proc. to return the records for a culture. However, ...

SQL Query NOT Between Two Dates

Hello all, I need some help with SQL Query. I am trying to select all records from table test_table which would not fit between two dates '2009-12-15' and '2010-01-02'. This is my table structure: `start_date` date NOT NULL default '0000-00-00', `end_date` date NOT NULL default '0000-00-00' ----------------------------- **The foll...

What does a "set+0" in an SQL statement do?

Hi, I'm baffled as to what this SQL statement means: SELECT exhibitor_categories+0 from exhibitor_registry What is exhibitor_categories+0 ? It returns a number for each row returned. exhibitor_categories is defined as: set('contemporary', 'classical impression / transitional', 'outdoor', 'home accessories') Thanks for your time :...

insert if not exists oracle

I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: INSERT ALL IF NOT EXISTS( SELECT 1 WHERE fo.primary_key='bar' ) ( INSERT INTO schema.myFoo fo ( primary_key, value1, va...

Database trouble in Django: can't reset because of dependencies

I'm trying to reset a database in Django, using: python manage.py reset app but get the following error: Error: Error: app couldn't be reset. Possible reasons: * The database isn't running or isn't configured correctly. * At least one of the database tables doesn't exist. * The SQL was invalid. Hint: Look at the output of 'djan...

Getting Number of Rows in a Group By Query with Microsoft Access

I have basically the same problem outlined in this question, however I am using Microsoft Access as a database instead of MySQL. The result of which is that SQL_CALC_FOUND_ROWS doesn't seem to be available to me. Believe me, I want to switch, but for the moment it is out of the question. I have a query that aggregates a number of ro...

How do I use PL/SQL to_date with a variable in Groovy?

I've got the following small Groovy script that just does a count of rows in the database for a specific date. import groovy.sql.Sql def today= new GregorianCalendar() def dateString = "${today.get(Calendar.MONTH)+1}/${today.get(Calendar.DAY_OF_MONTH)-1}/${today.get(Calendar.YEAR)}" def sql = Sql.newInstance("jdbc:oracle:thin:bc/bc@ne...

Mysql: Query to find row with max with tie breaker

User Region Points Last_Updated 1 5 0 1-Nov-09 I want this row 2 1 5 30-Oct-09 3 1 2 02-Nov-09 2 2 7 02-Nov-09 and this row 3 2 5 02-Nov-09 Using a mysql database, I want to gra...

Selecting records in SQL based on another table's contents

I'm a bit new to SQL and have trouble constructing a select statement. I have two tables: Table users int id varchar name Table properties int userID int property and I want all user records which have a certain property. Is there a way to get them in one SQL call or do I need to first get all userIDs from the propert...

ONE TO ONE LEFT OUTER JOIN

Hi everybody, I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, but there exists only ONE record that match that condition, so when it found its pair on B, it must stop and continue with th...

PostgreSQL , Select from 2 tables, but only the latest element from table 2

Hey, I have 2 tables in PostgreSql: 1 - documents: id, title 2 - updates: id, document_id, date and some data: documents: | 1 | Test Title | updates: | 1 | 1 | 2006-01-01 | | 2 | 1 | 2007-01-01 | | 3 | 1 | 2008-01-01 | So All updates are pointing to the same document, but all with different dates for the updates. What I am try...

Wrestling with SQL

I have this in a MySQL db: table Message sender_id int recipient_id int created datetime [title, body, etc... omitted] Is it possible to get from this, in a single query, a list of all the users who have been communicating with a given user with id N (meaning N appears in either sender_id or recipient_id), ordered by c...

What is a batch?

In Transact-SQL, a batch is a set of SQL statements submitted together and executed as a group, one after the other. Batches can be stored in command files. Is an *.sql file containing several SQL statements considered a batch? What else do we consider a batch? ...

The Return statement

Hi Assuming A.sql contains the following code, then second Select query won’t be executed due to Return statement: select * from Films; return; select * from Films; If A.sql was called inside a stored procedure SP1 or batch B1, then RETURN would transfer control back to SP1 or B1, respectively. But assuming A.sql isn’t called f...

Access SQL query: find the row with the most recent date for each distinct entry in a table

All, I'm sure this is a pretty simple SQL query question, but I'm sure there's a good way, and a very BAD way, to do this. Left to my own devices, I'm liable to end up with the latter. So... I have a table in Access with data that looks like this: ID Value As_of 1173 156 20090601 1173 173 20081201 1173 307 200...

Why do SQL INSERT and UPDATE Statements have Different Syntaxes?

While contemplating this question about a SQL INSERT statement, it occurred to me that the distinction in syntax between the two statements is largely artificial. That is, why can't we do: INSERT INTO MyTable SET Field1=Value1, Field2=Value2, ... or UPDATE MyTable ( Field1, Field2 ...) VALUES ( Value1, Value2, ... ) WHERE some-k...

Multiple columns (one per type) vs. single TEXT/Clob column

I need to store some diffs of other tables' columns in the database. I want to use a single table. Option A Table with 4 columns: id content_type (VARCHAR 255, will be: datetime, integer, varchar, text/clob ...) old_content (CLOB / TEXT, software serialized data for content-type) new_content (CLOB / TEXT, software serialized data for...