sql

ON DUPLICATE KEY UPDATE with a multi field index

I have this test table with one row entry and 2 indexes, the first a primary key and then a unique index for a and b columns: CREATE TABLE IF NOT EXISTS `test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `a` int(11) NOT NULL, `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `a` (`a`,`b`) ) ENGINE=InnoDB...

Adding one month to date if two values fall withinin same month, and then repeating the validation check (recursion?)

I have some rather dodgy data I'm looking at, and I've been tasked with finding out for how many consecutive months something has been going on for. However I have noitced that in some of my reference tables individual date values are being miscoded, and where there are multiple values in one month, the latest should be added into the ne...

Can I drop one of these indexes in Wordpress?

Hi guys, i'm currently exceeding the maximum server queries per hour with my blog on my host, and when that happens they shut my account down, rendering it useless. I keep exceeding the maximum amount of queries which is 75,000 but I don't think I should be considering the amount of visitors I have at the moment, plus I'm using Super C...

Primary key violation constraint

string sqlInsert = "Insert into account_details( account_number, account_type, transfer_access_code, account_balance, customer_id) SELECT account_number, account_type, transfer_access_code, account_balance, customer_id from customer_details"; This query just takes data from customer ...

ORA-00905: Trouble converting Mysql/MMSQL syntax to oracle syntax

Hi guys i'm having trouble running the below code on an Oracle DB not too sure why - getting ORA-905 error - missing keyword This works fine on MSSQL and MYSQL. Any indication as to how to fix will be much appreciated. Cheers. SELECT product.productId, product.version FROM product INNER JOIN (SELECT productId, MA...

sql insert query with subquery input and additional parameter

insert into sycle(name,password) values(select name from name_table,'name'); i am having problem in inserting additional value with the parameter received from the select subquery. it can be done in two query, but i want to kn ow if it can be done in a single query. ...

Granting privileges to ALL objects in a database - Postgres

Hi folks, I'm trying to backup my database with: pg_dump my_database > backup.sql unfortunately there are no privileges set for many objects in the database, therefore the command does not work! Furthermore this does not grant privileges as expected: GRANT ALL ON DATABASE my_database TO root Any ideas? ...

How to get list of all objects? - PostgreSQL

Hi folks, I need a list of the objects included in the db: tables, sequences, etc... Getting the list of tables was the only thing I was able to find out. Any ideas for what I could use in order to obtain everything? ...

What is Derby's equivalent of DB2's "NOT NULL WITH DEFAULT"

I'm investigating how feasible it is to change some unit tests (for an application running on DB2) to use Derby. Having found this question where the answer claims that DB2 and Derby are very compatible, it seemed like a possibility to take DDL out of the DB2 database and run it on a Derby database. But I seem to have found a case where ...

row with minimum value of a column

Having this selection: id IDSLOT N_UM ------------------------ 1 1 6 2 6 2 3 2 1 4 4 1 5 5 1 6 8 1 7 3 1 8 7 1 9 9 1 10 10 0 I would like to get the row (only one) which has the minimun value of N_UM, in this case the row with id=10 (10 0). ...

user default column value in INSERT stored procedure

From my ASP.NET application I am calling an INSERT stored procedure, there is a default value for one of the columns in the table that the INSERT procedure places the data into. How do I specify that I want the default value to be used instead? (Or do I have to specify the actual default value in my parameters) SITUATIONAL TABLE: Colum...

Match similar zip codes

Background To replace invalid zip codes. Sample Data Consider the following data set: Typo | City | ST | Zip5 -------+------------+----+------ 33967 | Fort Myers | FL | 33902 33967 | Fort Myers | FL | 33965 33967 | Fort Myers | FL | 33911 33967 | Fort Myers | FL | 33901 33967 | Fort Myers | FL | 33907 33967 | Fort Myers...

How do I help a person who wants relational database data in a CSV format?

The non-technical person who asks, "Can you just put the database in an Excel spreadsheet for me?" is so common it's almost a trope. (I could've sworn there was an xkcd about this, but I can't find it.) We regularly get customers asking for all their data in a CSV. To say this person is non-technical is redundant, so I need to explain t...

Daily SQL Task to delete contents from a table

Hey I was wondering how I could set up a clean up task on a particular table to delete contents thats lets say a week old. I am using SQL Server 2005 ...

Selecting the latest values given data with missing records

... where "missing records" are identical to the last recorded value, hence no record. This may be subjective, but I'm hoping there's a standardised way of doing this. So, let's say I have a bunch of analytics in a MySQL table. There is some missing information, but as mentioned above, that's because their previous value is the same as...

nested set and treeview control

Hi All, Given the following database tables and sample data: Locations Id ParentId LeftIndex RightIndex Description -- -------- --------- ---------- ----------- 34 2 85 104 Florida Region 73 34 94 95 Miami Products Id ParentLocationId Code Description -- ---------------- -...

Switching from Oracle 10g Express to SQL Server Compact (NHibernate)

Hey, I am switching my application from Oracle 10g to SQL Server Compact. Currently I have this in the mapping file: <id name="Id" column="MY_ID"> <generator class="sequence"> <param name="sequence">MY_SEQ</param> </generator> </id> and I have been informed that sequence does not exist in SQL Server Compact, I was wondering i...

Getting result of dynamic SQL into a variable

Hi, Executing dynamic SQL as follows in Stored Procedure: DECLARE @sqlCommand nvarchar(1000) DECLARE @city varchar(75) SET @city = 'London' SET @sqlCommand = 'SELECT COUNT(*) FROM customers WHERE City = @city' EXECUTE sp_executesql @sqlCommand, N'@city nvarchar(75)', @city = @city How do I use the count(*) column value as return valu...

Firebird configuration - turn case-sensitivity off

I'm looking to perform case-insensitive search in a Firebird database, without modifying actual queries. In other words, I'd like all my existing "SELECT/WHERE/LIKE" statements to retrieve BOB, Bob, and bob. Does Firebird configuration allow to modify this behavior? ...

How to trace back the exact create table statement that was used to create a table ?

Hi all, Is it possible to trace back the exact create table statement that was used to create a table ? Thanks, Trinity. ...