sql

How to store data into MySQL database?

I have created a java application which stores data into MySQL database. For that I have done the following things: I have installed MySQL database on my computer. I have created a database on that MySQL server. I have created a table in the database with the required schema. Now I want to deliver this application to various clients...

Query through linked server is very slow

I have 2 SQL 2005 servers SRV1 and SRV2. SRV2 is the linked server on SRV1. I run a storep proc with params on SRV2 and it is completed immediately. But when I run the same proc through the linked server on SRV1, for example EXEC [SRV1].DB_TEST.dbo.p_sample_proc it takes about 8-10 minutes to complete. After restarting SRV2 the problem ...

Generating a random winner and displaying the odds of winning - am I doing this right?

I'm running a contest on a website and I have 3215 entrants who are eligible for 5x Sony PSPs. I believe the formula to count the odds is totalEntrants - prizes / prizes: (3215-5)/5 = 642 so that's an odds of 642 to 1 of winning - is that right? ( I suck at math ) And in my table which contains 3215 rows in the database I would just s...

When do i use inner joins and when do i use subqueries?

What is the difference between an inner join and a subquery? and when should i use a subquery? or an inner join? I was in a situation recently where an inner join was too slow and subquery was the solution. From my limited understanding i thought the two worked exactly the same. ...

Asking for everything "up to" a value [MySQL]

If I would like to: SELECT * FROM `Students` ...from age 0 to 20, how would I do this? ...

Error in when comparing British format date in where clause.

When I run this in sql server2005 I got error. select * from productratedates where RateDate BETWEEN '31/10/2009' AND '03/11/2009' Error: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. But When I run this in SQl server 2005. It is perfectly all right. select * from productrate...

Sql query to Group by day

I want to list all sales, and group the sum by day. Sales (saleID INT, amount INT, created DATETIME) Update I am using SQL Server 2005 ...

My database doesn't insert immediately

Hi, I am a trying to apply Test Driven Development to producing a web page and am having trouble using my database. I am developing using Cake 1.1, PHP5 and SimpleTest to unit test. My problem is that I have a test that: Inserts a row using a direct SQL statement Tests if that row was inserted (by using a function in my main program....

Find the longest sequence of a value in a table

This is an SQL Question, I think it is difficult one - I'm not sure it is possible to achieve in a simple SQL sentence or a stored procedure: I want to find the number of the longest sequence of the same (known) number in a column in a table: example: TABLE: DATE SALEDITEMS 1/1/09 4 1/2/09 3 1/3/09 3 1/4/09 ...

What is a good free RDBMS solution for a small web project that may grow large if successful?

As a C# developer that uses MS SQL Server heavily I'd prefer to use what I know; however, for a small project the licensing costs are prohibitive and so I'm looking at using a free open source solution such as MySQL. Which of the free RDBMS solutions are the best in terms of stability, performance, features and ease of use for someone fa...

Query to pull sum from 2 different tables, is this possible in one query?

Thanks for all the help so far, now I just ran into a major problem! I have 2 tables that contains daily commissions, and for each day, I have to SUM the daily totals from each table. Daily limit is maxed at $100, so anything over $100 for the day is $100. Employee (employeeID INT PK, totalCommisions INT ) Now the 2 tables that conta...

Doesn't Equal in SQL

Hi Everyone: I am wondering if there is some way to do a doesn't equal command in MYSQL. In other words, can you do a command like this: "SELECT * FROM someTitle WHERE someLabel != 'something'"? My code is returning an error when I attempt this. Thanks for any help! ...

Downsides to "WITH SCHEMABINDING" in SQL Server?

I have a database with hundreds of awkwardly named tables in it (CG001T, GH066L, etc), and I have views on every one with its "friendly" name (the view "CUSTOMERS" is "SELECT * FROM GG120T", for example). I want to add "WITH SCHEMABINDING" to my views so that I can have some of the advantages associated with it, like being able to index ...

Doctrine - How do you ask WHERE cond1 AND ( cond2 OR cond3)

While using Doctrine in a Symfony project I've come into the situation where I need to apply a condition and then one of two following conditions (which both happen to be sub-queries). I know of the andWhere() and orWhere() functions, but am having trouble using these to generate things like: WHERE cond1 AND ( cond2 OR cond3) ...

How to query MySQL DB from client in a secure manner

I'm doing a personal number-crunching project, and I'd like to launch multiple programs on multiple computers (maybe even on Amazon's servers someday), and have them all storing and sharing data in a common SQL database, located on my web hosting account. The hosting company won't allow foreign connections directly to the SQL server, bu...

SQL Server - two statements on one line??

How to I pass this to SQL Server, it seems to want the "Go 4" on a second line? Insert Into tbl Values (896,0) GO 6 ...

Deleting similar columns in SQL

In PostgreSQL 8.3, let's say I have a table called widgets with the following: id | type | count -------------------- 1 | A | 21 2 | A | 29 3 | C | 4 4 | B | 1 5 | C | 4 6 | C | 3 7 | B | 14 I want to remove duplicates based upon the type column, leaving only those with the...

Generate missing dates + Sql Server (SET BASED)

I have the following id eventid startdate enddate 1 1 2009-01-03 2009-01-05 1 2 2009-01-05 2009-01-09 1 3 2009-01-12 2009-01-15 How to generate the missing dates pertaining to every eventid? Edit: The missing gaps are to be find out based on the eventid's. e.g. for eventid 1 the output should be 1/3/2009,1/4/2009,1/5/2...

PostgreSQL Update not returning zero count

Hi folks, I tried to update a particular record with same value again and again, but it returns the affected rows value as 1 always. update users set active = 1 where id = 304 1 row(s) affected. again the same query update users set active = 1 where id = 304 1 row(s) affected. but the second update should return 0 row(s) affected...

mysql column data copy from one table to another with a join?

Having trouble figuring out the syntax for this one... :-/ Table 1 ID FEE FAI FOE 0 Fee1 Fai1 Foe1 1 Fee2 Fai2 Foe2 2 Fee3 Fai3 Foe3 Table 2 ID FEE FAI FUM - Fee1 Fai1 Fum1 - Fee2 Fai2 Fum2 - Fee3 Fai3 Fum3 Based on the shared columns FEE and FAI, which when combined form unique pairs, I'd like to...