query

Massive SQL query design ideas

Need to query a database for 12 million rows, process this data and then insert the filtered data into another database. I can't just do a SELECT * from the database for obvious reasons - far too much data would be returned for my program to handle, and also this is a live database (customer order details) and I can't have the database ...

What does ":P" mean in a JDO query

I am using JDO on google app engine. Each 'Employee' has a 'key'. I have a set of keys and wanted to retrieve all Employees whose key belongs to this set. So I implemented it using the 'contains()' filter as specified here. The code works fine and looks like this - List<Key> keys = getLookupKeys(....) ..//Get keys from somewhere. Quer...

How to insert date(y-m-d) into MySQL database ?

I have a field of type date in MySQL. When I try to insert any date in this field with PHP using following query, It stores 0000-00-00 in that field. For example: UPDATE test SET dob=2000-09-20 WHERE id=3 ...

postgresql full text search query to django ORM

Hi, I was following the documentation on FullTextSearch in postgresql. I've created a tsvector column and added the information i needed, and finally i've created an index. Now, to do the search i have to execute a query like this SELECT *, ts_rank_cd(textsearchable_index_col, query) AS rank FROM client, plainto_tsquery('famille age')...

MySQL - Show All Permutations?

Table1: Id MyFK f_name l_name =========================== 1 100 John Doe 2 100 Little Timmy Table2: Id MyFK item price =========================== 1 100 Car 200 2 100 Bike 100 In MySQL, how do I produce a table like this: Id MyFK f_name l_name item price ================...

String concat on MS SQL for a group of rows

Lets say I have 2 tables: 1 with users and another one which keeps record of which users used what codes. Users ----- Id, Name 1, 'John' 2, 'Doe' Codes ------ Id, UserId, code 1, 1, 145 2, 1, 187 3, 2, 251 Now I want to pull a query that results he following Name, UsedCodes 'John', '145,187' 'Doe', '251' How can this be done wi...

Need help with a complex SQL query

I have a stored procedure that uses this select statement: SELECT dbo.VendorProgram.id, dbo.VendorProgram.CODE, dbo.Programs.ProgramName + '-' + dbo.Divisions.Division + '-' + dbo.Vendors.Source + '-' + dbo.Mediums.Medium + '-' + dbo.VendorProgram.content AS SourceDe...

MS Access performace dlookup on query or dsum?

I know that all of the domain aggregate functions are slow, but I am looking for the least of the evils. Which will be the faster of the following two options? Create a query that will group by the unique value and sum the total. Have dlookup to get my sum from the query. Do a dsum on the main table with the criteria being the same as...

Optimization SQL Query For Analytics

I have implemented analytics system which is now performing very poorly. To explain it I need to explain table structure queries I have two innodb tables Table1: Contains records about hourly stats (stats_id, file_id, time) Table2: Contains over 8 million rows. Table 2 structure is full_stats ( stats_id Int file_id Int s...

SQL - How to Find YTD amount?

Let's say I have a table like this called hours: employee, payperiod, hours greg, 1/31/2010, 12 greg, 1/31/2010, 15 mark, 1/31/2010, 10 mark, 1/31/2010, 11 greg, 2/28/2010, 12 greg, 2/28/2010, 15 greg, 2/28/2010, 4 How would I find the year to date hours for a given employee and payperiod? For the above example I'd want to get to: e...

How to implement where clause on Android Query method?

I'm trying to query a word, for this Im using the db.query method. But I want use a where clause, I've done like this on my code, but, the emulator returns an error. public String select(String wrd) { String list = new String(); Cursor cursor = this.db.query(TABLE_NAME, new String[] {"word"}, "word like " + wrd + "", null, null...

NHibernate and SQLite: will an IgnoreCase() query be an indexed lookup or not?

The Foo column is defined as "Foo TEXT unique". Will an Eq().IgnoreCase() query use the index or will it perform a complete column scan? The query: string foo = "foo"; IList<T> list = session.CreateCriteria(typeof(T)). Add(Expression.Eq("Foo", foo).IgnoreCase()).List<T>(); ...

MySQL relational view - join?

I'm relatively new to MySQL and I'm having no end of difficulty trying to work out how to do this. I've researched joining and such but I'm not really sure how to apply this. I have three tables: Artists Table ID, Name, Description Albums Table ID, Title, Year, Artist_ID Tracks Table ID, Title, Album_ID Tracks are assigned to albums...

Access top n in group

I have a table where I need to get the top n highest amount items for each Category. Category Item InventoryCount ------- ----- ------------- Beverage milk 3 Beverage water 2 Beverage beer 9 Utensil fork 7 Utensil spoon 2 Utensil knife 1 Utensil spork 4 My desired output is the highest Inventory...

Subsequent queries depends on result of initial query: how to?

Say I have 3 queries. Query 1 returns a piece of information that Query 2 and Query 3 needs. Is there a way for Query 2 and Query 3 to access this piece of information from the result of Query 1? Right now, I have Query 1 executing twice: once in Query 2 and once in Query 3. This doesn't seem efficient to me. Is there a better way in M...

How to write a query in Core Data in iPhone

Hi friends, I have used core data in my apps. My application works fine in online and offline mode . I have doubt about, how to write a query in Core data(Similar SQLite). I wrote a query and used in SQLite. But i want to know about, how to write a query(select, insert, update, etc,.) using core data. Please guide me and give me some us...

Performing regex Queries with pymongo

I am trying to perform a regex query using pymongo against a mongodb server. The document structure is as follows { "files": [ "File 1", "File 2", "File 3", "File 4" ], "rootFolder": "/Location/Of/Files" } I want to get all the files that match the pattern *File. I tried doing this as such db.collectionName.find...

MySQL not pulling all rows.

Hey guys, first time using stackoverflow. can you guys help me debug? Heres the problem, this query is selecting all of the rows from my database, its only outputting the first one twice for some reason. $top10_query = "SELECT * FROM kicks"; $result = mysqli_query($cxn, $top10_query) or die("Couldn't execute query."); $row = mys...

How to get specified columns with result as array of table class objects?

Hello. I have simple problem. In my table have columns ID, NAME, CONTENT, TIMESTAMP. If i use session.query(table).all() result is array of table class objects. So i have no problem with modify one or more objects and update, or use this objects in associations. But i need only columns ID and NAME. If use session.query(table.id, table.n...

Getting last and next db-record by date in MySQL-Table?

Hey guys, I've got a certain question related to a blog, which I am developing in OOP (PHP) right now. All blogposts are stored in a MySQL-table. In the app you can read a specific post by giving the id of the post via GET-parameter. So like http://example.com/?id=2. Under the blogpost I want to show to navigation links like "previous"...