sql

N Top Record Selection Based on Own SQL Statement in MS-Access

I'm re-writing a small ms-access application to take examinations on. What they want is for the tests to grab a set of random questions based on how large the exam's size is. If each exam was a set number of questions, I could just stick the number in the TOP statement and be done with it, but there are a variable number of questions ...

what is the query to return Name and Salary of employee Having Max Salary

what is the query to return Name and Salary of employee Having Max Salary ...

Count associations in sqlite database query?

I have a sqlite database with three tables: Notes, Lists, and Notes-in-Lists. Both Notes and Lists have an autogenerated id column and some extra data columns like title. Notes-in-Lists is an association table with an autokey, and two foreign keys that point to a Note id and a List id. I have a query that returns all notes in a given l...

Comparing large numbers in php and sql

I need to compare a very large number in php (30 digits long) with 2 numbers in my database. Whats a good way to do this? I tried using floats but its not precise enough and I don't know of a good way to use large numbers in php. ...

How can you tell what method a constraint was created with in SQL Server 2008?

There are two ways to create a constraint, Method A: ALTER TABLE dbo.<tablename> ADD CONSTRAINT <namingconventionconstraint> UNIQUE NONCLUSTERED ( <columnname> Method B: CREATE UNIQUE NONCLUSTERED INDEX <namingconventionconstraint> ON dbo.<tablename> ( <columnname> ) ON [PRIMARY] However, it appears that these constraints need to ...

Convert colums to rows in SQL

I need to write a query which takes rows and converts it into columns - here's my table: Count fname lname id ----------------------------- 1 abc def 20 2 pqr 20 3 abc xyz 20 4 xyz xyz 20 1 abc def 21 1 pqr xyz 22 2 abc abc...

MySQL: Multiple Inserts for a single column

I'm looking for a way to do multiple row inserts when I'm only inserting data for a single column. Here is the example table: +-------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+----------------+ | id | tinyint(4...

Why most SQL databases allow defining the same index twice?

Why most SQL databases allow defining the same index (or constraint) twice? For example in MySQL I can do: CREATE TABLE testkey(id VARCHAR(10) NOT NULL, PRIMARY KEY(id)); ALTER TABLE testkey ADD KEY (id); ALTER TABLE testkey ADD KEY (id); SHOW CREATE TABLE testkey; CREATE TABLE `testkey` ( `id` varchar(10) NOT NULL, PRIMARY KEY (`i...

SQLDatareader via CLR not returning SQL Message right way

I execute the following code via CLR, is there a reason why the message is not printed to the SQL Server, does it need to wait until the Stored Procedure returns all the rows (there is about 7 Billion rows to return) SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedu...

query related to in clause

I have two tables: table 1 fid field queryorder table 2 fid field name fid and field are same in both tables. I want a query like select fid from table 1 where field in table 1 corresponding to name = dell and should not have queryorder = 1 ...

Modeling products with vastly different sets of needed-to-know information and linking them to lineitems?

I'm currently working on a site that sells products of varying types that are custom manufactured. I've got your general, standard cart schema: Order has many LineItems, LineItems have one Product, but I've run into a bit of a sticking point: Lets say one of our products is a ball, and one of our products is a box of crayons. While peop...

Selecting Users signed up in past 30 days and in past 7 days in one efficient query

I have this query that selects the number of user signups in the past 30 days: SELECT COUNT(*) AS UserCount30 FROM User WHERE User.UserDateCreated > (CURDATE() - INTERVAL 30 DAY) Then I have this query that selects the number of users that signed up in the past 7 days SELECT COUNT(*) AS UserCount7 FROM User WHERE User.Use...

Connecting to SQL Server Database C#-WinForms

I have a desktop app that I'm making and I want users to have to login before the program can be used to its fullest extent. I have created a database on www.winhost.com (where my site's hosted), but now I don't know what to do. I've been on google and msdn and I would like to know how to programmatically add new rows/colums to this new ...

How do I find Stored Procedures with wrong text in syscomments

There appears to be several stored procedures that were renamed with sp_rename, causing the syscomments to be left with the old proc name instead of the new proc name. Thus, my db transfers are failing to transfer correctly. Is there a way to find which procs (or any objects) have their names out of synch? Or better, a simple way to f...

default a column with empty string

Is there a way, via a SQL statement, to ensure a column's default value is an empty string '' instead of NULL? ...

Update tables with same name different schemas

Using SQL Server and T-SQL, how can I update ALL tables tables with a specific name but different schemas under the same database? :Update: The updates include adding/deleting/modifying columns as well as changing specific values of rows. I want to be able to deploy changes to a table across all schemas. Using the SQL Server Managemen...

How to create a list of seconds in MySQL

I have the following query: SELECT timestamp, COUNT(*) FROM table GROUP BY timestamp But some timestamps do not show up because there is no data. Here's an example 1:00:00 | 3 1:00:02 | 17 1:00:03 | 2 Notice that 1:00:01 is missing. Is there a way to make the 1:00:01 | 0 appear in the result? ...

CLR: System.InvalidOperationException: The context connection is already in use.

I keep getting this error when trying to perform a delete in the middle of my DataReader: System.InvalidOperationException: The context connection is already in use. I get all the rows that need to be deleted and then iterate through the data reader as there are a lot of rows returned. SqlConnection conn = new SqlConnection("context c...

Merging result from 2 columns with same name and not over-writing one

I have a simple MySQL query like: SELECT * FROM `content_category` CC , `content_item` CI WHERE CI.content_id = '" . (int)$contentId . "' AND CI.category_id = CC.category_id AND CI.active = 1 Both tables have a column called configuration one of which gets overwritten in the query i.e only content_item.configuration is ret...

Is F Sharp the right programming language for what I want to accomplish?

I recently downloaded Visual Studio 2010 and would like to know if this multi-paradigm programming language is the right language for what I what I want to accomplish.. I don't have any experience with OOP, rather I'm an ole school procedural language programmer. I also downloaded an eval version of RADvolution Designer. My goal is to co...