sql

Is it possible to update 3 sql rows in 1 sql update statement

Hi, I have a SQL table like this. id Order ======== ========= 1 4 2 3 3 5 4 1 5 2 Is it possible to update multiple rows in 1 sql statement? i.e. I want to update id = 3, order = 1 and id = 5, order = 4 and id = 1, order = 1 I know how to do that in ...

sql query to get content older than 3 weeks.

My content table looks like (contentID, title, created). I need to get all content that was created more than 3 weeks ago. Sql server database, created is datetime type. ...

GROUP BY behavior when no aggregate functions are present in the SELECT clause

I have a table emp with following structure and data: name dept salary ----- ----- ----- jack a 2 jill a 1 tom b 2 fred b 1 When I execute the following SQL: SELECT * FROM emp GROUP BY dept I get the following result: name dept salary ----- ----- ----- jill a 1 fred b ...

MySQL Migration Script Help

I am working on a site that lists a directory of various restaurants, and currently in the process of switching to a newer CMS. The problem I have is that both CMSes represent the restaurant data differently. Old CMS A Cross Reference Database so it may list an entry for an example like this: ID / FieldID / ItemID / data 3 / 1 / 6 / ...

DATE_ADD problem

Hi I am working to add 1 month to date() and save it in my field on database. I use this $query2 = "SELECT * ,DATE_ADD(`date_joined`,INTERVAL 30 DAY) AS expire FROM `set` WHERE ID='$idno'"; $result2 = mysql_query($query2); "expire" is the field i want to save as +30 days. date_joined is current date. but it doesn't work. expire ...

mysql performance

I'm testing MySQL as a replacement for SQL server and I'm running into something really strange. I'm testing both inserts and reads, and maxing out around 50 queries per second either way. My test table looks like: DROP TABLE IF EXISTS `webanalytics`.`test`; CREATE TABLE `webanalytics`.`test` ( `id` int(10) unsigned NOT NULL AUTO_...

Dense_Rank() alternative in sql server 2000?(Set based)

Actually, I have the task of finding the employees based on the salary rank. So I used Dense_Rank() and got the answer. Initially I was told to solve in SQL SERVER 2005. Later on they changed the requirement and is saying that the query should run in SQL SERVER 2000 also. I solved that using a while loop. But they are saying that...

How to display multiple values in a MySQL database?

I was wondering how can you display multiple values in a database for example, lets say you have a user who will fill out a form that asks them to type in what types of foods they like for example cookies, candy, apples, bread and so on. How can I store it in the MySQL database under the same field called food? How will the field food ...

DB2 automatic trim tailing whitespace

This is data in TB_USER table USER_USERID -------------- A111 A9999 ADMIN AHO AHO2 AHO3 AHO4 ...and schema of TB_USER table is COLUMN_NAME DATA_TYPE DATA_LENGTH -------------------- --------- ----------- USER_USERID VARCHAR ...

CakePHP mathematic-calculation field?

(Database structure like http://stackoverflow.com/questions/1545764/cakephp-select-default-value-in-select-input) So, I have two tables in CakePHP: Trees, and Leafs. Every Leaf has a tree_id for its corresponding tree. Every leaf also has a numeric value. The default view that I baked for trees just lists all the trees in a table. I...

Counting rows in multiple tables

I have a mysql database that is tracking hockey stats. What I'd like to do is in one query get the number of goals and assists scored by each player as well as the number of games that they've played in. I'm using Zend Framework and the query that I've build is this: SELECT `p`.*, `pxt`.`jersey_number`, count(pxg.playe...

strange SQL server report performance problem related with update statistics

I got a complex report using reporting service, the report connect to a SQl 2005 database, and calling a number of store procedure and functions. it works ok initially, but after a few months(data grows), it run into timeout error. I created a few indexes to improve the performance, but the strange thing it that it works after the inde...

Opposite of INTERSECT in Oracle

I have two selects and I want to combine them in such a way, that only rows unique in both selects are returned. Is there any built-in way in Oracle 10g to achieve this? I know I can do something like this: (select1 UNION select2) MINUS (select1 INTERSECT select2) but I would like to avoid it. Both select1 and select2 have 20 lines,...

Visual Studio 2005 doesn't support Sql Server 2008

I'm developing Reporting services on VS2005 and have to connect to SQL Server 2008. The following Error occurs: "This server version is not supported. You must have Microsoft SQL Server 2005 Beta 2 or later." I found on the net a patch for it, but it doesn't work (link to patch) "The upgrade patch cannot be installed by the Windows I...

a subquery within a subquery - is it possible?

Hi All, I have this sql below that i use to compare values of z. I put z in a subquery and then compare it. My qn is in in my else statement below, i want to put in another formula to calculate something else of which the info is only available in another table called var1(for example, n). i would like to put in sum(n)/count(n) to en...

how to run query that contain ( ' ) ? ex: select * from A where B like 'aa'bb' ??

Hi How do I run a query that contains ( ' ) ? For example: select * from A where B like 'aa'bb' Working on Oracle 10g Thanks in advance ...

stop sql insert in a for or while loop

i created a loop up to 100 to insert any data in db. but when i close my browser I hope it stops but it in background it continues looping and filling my db. how can I stop it? thanks ...

SQL: how to select single record for multiple id's on the basis of max datetime?

I have the following SQL table, Id WindSpeed DateTime -------------------------------------- 1 1.1 2009-09-14 16:11:38.383 1 1.9 2009-09-15 16:11:38.383 1 2.0 2009-09-16 16:11:38.383 1 1.8 2009-09-17 16:11:38.383 1 1.7 2009-09-19 16:11:38.382 ...

Are there any programs that will shrink the size of a sql script file?

I have a SQL script which is extremely large (about 700 megabytes). I am wondering if there is a good way to reduce the size of the script? I know there are code minimizers for JavaScript and am looking for one to use with SQL scripts. I am not looking to get performance on the SQL script. I am trying to make the file size smaller. Rem...

Optimizing my mysql statement! - RAND() TOO SLOW

So I have a table with over 80,000 records, this one is called system. I also have another table called follows. I need my statement to randomly select records from the system table, where that id is not already listed within the follows table under the current userid. So here is what I have: SELECT system.id, system.u...