sql

Standard(s) for client-side definition of advanced search?

Is there some kind of established standard or search-meta-language for defining advanced search? Some defined standard for the use of wildcards, logical operators, labels or categories etc.? Something like Googles possibility to use "OR", "+" etc for logical definitions, "label:news" for specifying a category etc.? (This client-side "m...

Drawing a line in PostGIS using Nearest Neighbour Method

This is a cross post from an email I sent to the PostGIS mailing list So far in my endeavor to create a line between a point and its projected location on a line has been long but I'm almost there. As of yesterday, and before including any nearest neighbor analysis, I got the results shown in this image: As you can see, each point in...

mysql - how many columns is too many?

I'm setting up a table that might have upwards of 70 columns. I'm now thinking about splitting it up as some of the data in the columns won't be needed every time the table is accessed. Then again, if I do this I'm left with having to use joins. At what point, if any, is it considered too many columns? ...

(SQL) Pulling specifc data from a big list where certain dates fall within a specific quarter.

So I need to pull the e-mail addresses of members who have not logged into my site in the past 30 days. Since the site is over a few years old, we want to pull only a handful of each member from certain Quarters of the year. So for instance, there are about 800,000 people who haven't logged in within the past 30 days. So we want to pu...

What are some methods for persisting customer configurable data in a database?

I'm looking for some ideas on methods for persisting customer configurable data in a relational database (SQL Server 2000 in my case). For example let's say you have a standard order entry application where your customer enters a product they want to buy. In addition to the fields that are important to both you and the customer (item...

Automating problem query identification in Oracle 11g

In our test bed, a number of test suites will be run in a row (unattended), producing reports for later consumption. I want to include in those reports queries which are candidates for further investigation, along with the data that justifies their inclusion in that list. We should be able to associate any query identified this way wit...

How to re-write the following mysql query

I have a file upload site, and I want to run a maintenance script that will run every day and delete items that haven't been accessed in a week. I log views for each day, and each item into a table: hit_itemid hit_date hit_views The main table actually has the files that were uploaded, for the purposes of this example, its just vid_...

NHibernate: simple delete orphan scenario not working

I'm trying to have a simple one to many relationship/hierarchy using NHibernate. I would like orphans to be deleted automatically but my current attempts to do so all result in an ObjectDeletedException. I'm wondering if someone can tell me what I'm doing incorrectly. EDIT: I should have specified that I'm loading a root Foo, then remo...

Insert data into one column from two other columns of the same table

I have the following table: Table A FNAME | LNAME james | Bond John | Brit raje | van I want to insert first letter from first column with full last name to create a new username column for the table: Table A USERNAME jbond jbrit rvan If this is not possible, I at least need to update the lastname from lname to newly created user...

SQL Query (Like) Trying to find Titles with AND

When doing a SQL Query and I want to pull up entries from a table that have AND in the name, but I do not want names that just have and in them..... Confusing, but I'll show an example 2 Entries in the table : Pandomniam, and Frank and Beans. When I do the query I just want Frank and Beans to come up, not Pandomniam. I am doing som...

using tuples in sql in clause

Given a database like this: BEGIN TRANSACTION; CREATE TABLE aTable ( a STRING, b STRING); INSERT INTO aTable VALUES('one','two'); INSERT INTO aTable VALUES('one','three'); CREATE TABLE anotherTable ( a STRING, b STRING); INSERT INTO anotherTable VALUES('one','three'); INSERT INTO anotherTable VALUES('two','three'); COMMIT; I would lik...

is TSQL the right tool to product "transposed" query

I have a task which require the data manipulation to transpose the rows to columns. The data is stored in SQL Server, typical relational database model. I know it can be done with TSQL, but it is so complex that there are almost ten different row groups to be transposed to about 200 columns. Just wondering whether there is other better...

Simplified SQL Min Statement

The SQL below returns any records with min number and it should work fine: SELECT Id, Number FROM TableA WHERE Number = (select Min(Number) from TableA) Is there way I can write a SQL without the sub Select statement, but still returns the same result? ...

SQL qn:- comparing data in rows

hi, i would like to compare numeric data in rows. for eg, i have a table that has a column as such:- Number ====== 1.88 9.99 8.76 9.88 I want to compare 2nd value, 3rd value, 4th value to the 1st value. And then 3rd, 4th value to the 2nd. then 4th to 3rd. How can i construct an sql to do this? ...

sql query taking too long

Hi, I have simple "insert into.." query which is taking around 40 seconds to execute. It simply takes records from one table and inserts into another. I have index on F1 and BatchID on the tbl_TempCatalogue table 146624 records are effected. select itself is not slow insert into is slow. The complete query is insert into tbl_ItemPr...

Sql Server : How to use an aggregate function like MAX in a WHERE clause.

I want get the maximum value for this record. Please help me: SELECT rest.field1 FROM mastertable AS m INNER JOIN ( SELECT t1.field1 field1, t2.field2 FROM table1 AS T1 INNER JOIN table2 AS t2 ON t2.field = t1.field WHERE t1.field3=MAX(t1.field3) -- ...

How to stop inserting records in SQL table when a limit is reached

Hi, I am using VB.net and SQL Server 2005. My Problem is that I want to give user a message if the delegate limit has reached for that course. See I have a course where I have MinDelegate and MaxDelegate limit. I want to stop inserting and give user message that "Max Delegate limit has reached can't have more delegates for this course...

How can I write a SQL query that finds all entries in the database where a particular column occurs twice or more?

I have a table called Laptop that has a column named "HD". How can I write a query that will find all "HD" entries that occur twice or more? [HD] 10 20 20 40 50 10 So, out of those entries in HD, the query will return 10, and 20 because they both occur twice or more. ...

How to know if MATERIALIZED VIEW update is running?

I'm talking about oracle. I have a few materialized views, and they're updated from time to time (it is done with a scheduled task). It is easy to know last refresh date - just query USER_MVIEW_REFRESH_TIMES. And is there any way to know if some views are being updated in the current moment? ...

MS SQL Join on dateTime

Hi I have a query that joins two tables. The join is done on several columns, including a dateTime column. The problem that I have at the moment is that the one dateTime column stores milliseconds whereas the other table is populated from a file which does not contain milliseconds Because of this the join will never return results. Is t...