sql

How can a do a "greatest-n-per-group" query in django?

(This is the django version of the thread at http://stackoverflow.com/questions/2111384/) Suppose I have a table of customers and a table of purchases. Each purchase belongs to one customer. I want to get a list of all customers along with their last purchase. Can it be done without raw SQL and without multiple database queries? ...

Codeigniter/PHP delete row after period of time...

Is it possible to delete a SQL db row after a period of time? ie. I have a row that has an expiration date and it needs to be deleted on that day? If I'm displaying info to a user, is it better practice to just hide "expired" entries and keep the data? ...

Join tables SQL Server

I want to join two tables but I want the result set to only show matches that arent in the right side. Example: LeftTable leftID | PK value | RightTable rightID |PK leftID |FK select l.value from LeftTable l join RightTable r on l.leftID = r.leftID I know this wont give me what I want, but I am just trying to find o...

How to see errors in Oracle?

I am getting the following error when trying to execute a stored procedure in Oracle that contains two input parameters: ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'P_GET_NEXT_AVAILABLE_RUN' ORA-06550: line 1, column 7: PL/SQL: Statement ignored Both input parameters require values...

eBooks available covering Delphi, Sql, Asp, C#, Html, Css ?

I am considering buying an ebook reader (from Sony if you want to know). Do you know of any sites where you can (legally preferable) download/buy ebooks covering Delphi, Sql, Asp, C#, Html, Css , ... ? It would be nice to have reference books available on my ebook reader when I am developing software and web sites. ...

Date of max id: sql/oracle optimization

What is a more elegant way of doing this: select date from table where id in ( select max(id) from table); Surely there is a better way... ...

SQLITE3 2 level join with aggreation on middle level

we have 3 tables: grandfathers, fathers, sons. grandfathers have many fathers, and fathers have many sons, through the foreing keys grandfather_id and father_id. Each record has only one property, the name of the person. What I want is to have a list of all grandfathers, each with a field called grandsons_names which is the csv of all ...

Finding duplicate rows in SQL Server

I have a SQL Server database of organizations, and there are many duplicate rows. I want to run a select statement to grab all of these and the amount of dupes, but also return the ids that are associated with each organization. A statement like: SELECT orgName, COUNT(*) AS dupes FROM organizations GROUP BY orgName ...

Strategy for storing supplemental data alongside imported data

I have ran into this problem a few times and I am wondering what other people are doing. When I am creating a database, sometimes I have to import data into a table on a regular basis, let's say daily. What I normally do is delete all of the records and reimport every record from the external data source. Many times I will have to stor...

Is there a way to query a VB Script Array?

I'd like to be able to query an array (multi and single dimensional ) with something like SQL. Is there a way to do this? It just seems extraordinarily wasteful to step through it one record at a time. ...

SQL Server Date format Issue

I have this query to display records based on date Select * From orders Where CONVERT(VARCHAR(50), Orderdate, 101) = CONVERT(VARCHAR(50),'1/21/2010', 101) Though there are orders for today, the query is failing because the date passed is not 01/21/2010 How can I fix this issue in the query itself as the date passed by the other ...

How does sql optimization work internally?

My previous question: http://stackoverflow.com/questions/2112567/date-of-max-id-sql-oracle-optimization In my previous question, I was finding different ways of finding the date of the record with the highest id number. Below are several of the offered solutions, and their 'cost' as calculated by explain plan. select date from table ...

Updating an "order" column MySQL?

What's the best way to update an "order" column? Say I have an id column with 0 to 9, and order column from 0 to 9. Currently, it's in the database as: 0 0, 1 1, 2 2, etc My HTML page posts what it wants as the new order: 0 8, 1 3, 2 6, etc. (This is completely random, decided by the user). What's the best way to make the update? I...

Does it make sense to use an index that will have a low cardinality?

I'm mainly an Actionscript developer and by no means an expert in SQL, but from time to time I have to develop simple server side stuff. So, I thought I'd ask more experienced people about the question in the title. My understanding is that you don't gain much by setting an index in a column that will hold few distinct values. I have a ...

Caching data from SQL database for sorting

I got a MySql database that I do some potentially large queries to. The data I get from the query is stored in a 2D array in PHP which then generates a HTML table for the user to see. Currently I'm trying to implement a way to sort the data in various ways for the user. Of course I could just call the query again and tell it to sort in a...

TSQL - Help with UNPIVOT

I am transforming data from this legacy table: Phones(ID int, PhoneNumber, IsCell bit, IsDeskPhone bit, IsPager bit, IsFax bit) These bit fields are not nullables and, potentially, all four bit fields can be 1. How can I unpivot this thing so that I end up with a separate row for each bit field = 1. For instance, if the original table...

DBMS for Payment Server Software

Can anybody tell me if usage of FireBird or PostgreSql can by used in a small e-mail payment or 1000 kiosk-terminal server's data management , which will mainly process very important financial data like balances, payment transactions ... ????? which open-source database server you will suggest in my case? I don't like MS SQL because it...

SQL: Is a query like this OK or is there a more efficient way of doing it, like using a join?

I often find myself wanting to write an SQL query like the following: SELECT body FROM node_revisions where vid = (SELECT vid FROM node WHERE nid = 4); I know that there are joins and stuff you could do, but they seem to make things more complicated. Are joins a better way to do it? Is it more eff...

String processing during table creation and inserting from another table

I have a table that contains file paths, like so: -------------------- |Files | -------------------- |path nvarchar(500)| -------------------- I want to split it into two tables, one containing unique directories and one containing filenames: --------------------------- |Files | ------------------------...

Is SQL the ''assembler'' of the NoSQL database world?

I recently came across http://www.fossil-scm.org/index.html/doc/tip/www/theory1.wiki by D. Richard Hipp, the developer responsible for SQLite. it go me thinking, is Fossil the only NoSQL database that uses SQL? Do others uses SQL as a 'High Level Scripting Language'? ...