query

mysql select multiple rows in join

Hi-- I have a simple mySQL problem-- I have two tables, one is a user's table, and one is a photos table (each user can upload multiple photos). I'd like to write a query to join these tables, so I can pull all photos associated with a user (up to a certain limit). However, when I do something obvious like this: SELECT *.a, *.b FRO...

How are databases efficient?

If databases can support up to millions of records, how is all of this data organized such that queries can be executed in a reasonable amount of time? ...

sql query with space in the value

How do I write where clause where the value has spaces: Actually I am using openJPA and I have to set parameter. The value i will be setting has a space, eg: String somevalue="firstname lastname"; query.setparameter(somevalue); I did this but doesnot work. Any suggestion will be appreciated. Thanks. ...

SQL select descendants of a row

Suppose a tree structure is implemented in SQL like this: CREATE TABLE nodes ( id INTEGER PRIMARY KEY, parent INTEGER -- references nodes(id) ); Although cycles can be created in this representation, let's assume we never let that happen. The table will only store a collection of roots (records where parent is null) and their...

FitNesse/Slim String Operators

Is it possible to express this in a Query Table in FitNesse with SLIM for .net: contains(data) startswith(data) endswith(data) I know from a previous question it was possible for FitNesse/Fit with cell handler loader. I'm looking for the equivalent in Slim. ...

Querying results on timestamp in mysql

Hi, I have series of records in a table called 'hits' and each record has the current_timestamp (ie. 2010-04-30 10:11:30) in a column called 'current_time'. What I would like to do is query these records and return only the records from the current month. I cannot seem to get this to work. I have tried a range of queries that don't w...

How to return empty cells for repeated values and keep only the cells which are different ?

I have a query that selects some fields to display from a table SELECT Field1, Field2, Field3, Field4 FROM table1 I want instead of returning : To return: How could I modify my SQL statement to return the second figure ? Or at least how to change the gridview properties of .Net to do so (if this is possible) ? ...

How to retrieve the rows (with maximum value in a field) having a another common field ?

I have a table; let it be called table1; with the following fields and data I need a query that returns the record with the maximum value in Field3 for each group of records having the same value in Field2. So that the query returns: How could this be done using SQL queries ? ...

Joining different models in Django

Let's say I have this data model: class Workflow(models.Model): ... class Command(models.Model): workflow = models.ForeignKey(Workflow) ... class Job(models.Model): command = models.ForeignKey(Command) ... Suppose somewhere I want to loop through all the Workflow objects, and for each workflow I want to loop through its Co...

SQL to insert latest version of a group of items

I’m trying to determine a good way to handle the scenario below. I have the following two database tables, along with sample data. Table1 contains distributions that are grouped per project. A project can have one or more distributions. A distribution can have one of more accounts. An account has a percentage allocated to it. The distri...

Linq Distinct on list

I have a list like this: List people age name 1 bob 1 sam 7 fred 7 tom 8 sally I need to do a linq query on people and get an int of the number distinct ages (3) int distinctAges = people.SomeLinq(); how? how? ...

MySQL query optimization JOIN

Hi, I need your help to optimize those mysql query, both are in my slow query logs. SELECT a.nom, c.id_apps, c.id_commentaire, c.id_utilisateur, c.note_commentaire, u.nom_utilisateur FROM comments AS c LEFT JOIN apps AS a ON c.id_apps = a.id_apps LEFT JOIN users AS u ON c.id_utilisateur = u.id_utilisateur ORDER BY c.date_...

can use more than 1 column in MySQL Group BY?

Hi, I want write these SQL Query: CREATE VIEW `uniaverage` AS SELECT `averagegrade`.`mjr`,`averagegrade`.`lev`, AVG(`averagegrade`.`average`) AS `uniAVG` FROM `averagegrade` GROUP BY `averagegrade`.`lev`, `averagegrade`.`mjr`; But MySQL Query Browser give this error: Operand Should Contain 1 column(s) I somewhere read...

Question about joins and table with Millions of rows

I have to create 2 tables: Magazine ( 10 millions of rows with these columns: id, title, genres, printing, price ) Author ( 180 millions of rows with these columns: id, name, magazine_id ) . Every author can write on ONLY ONE magazine and every magazine has more authors. So if I want to know all authors of Motors Magazine, I have to ...

Hibernate Query - Get latest versions by timestamp?

I have a database that is being used as a sort of version control system. That is, instead of ever updating any rows, I add a new row with the same information. Each row also contains a version column that is a date timestamp, so the only difference is the new row will have a more recent timestamp. What I'm having trouble with is writin...

Appengine (python) returns empty for valid queries

EDIT: Figured it out. For whatever reason the field in the index was called strWord instead of wordStr. I didn't notice because of the similarities. The file was auto generated, so I must have called the field that in a previous development version. I've got an app with around half a million 'records', each of which only stores three fi...

Question about Benchmark function in Mysql ( Incredible results ).

I have 2 tables: author with 3 millions of rows. book with 20 miles rows. . So I have benchmarked this query with a join: SELECT BENCHMARK(100000000, 'SELECT book.title, author.name FROM `book` , `author` WHERE book.id = author.book_id ') And this is the result: Query took 0.7438 sec ONLY 0.7438 seconds for 100 millions of que...

Query Notification Loop event OnChange when use view or join Table

hi when I use a join table (inner join or etc) in my command,OnChange Event in SQL dependency Object fire in loop. but when use a simple select statement It works fine. any body know why? ...

Help with random - sql server 2008 query

hi i have 4000 records, and i need to pick randomize 500 records. i need that 500 records will insert to GoodTable and the rest 3500 records will insert to BadTable how to do it using sql-server 2008 query ? thank's in advance ...

Data in column not changed

I have sql 2005 and when i run below query, data from RealTimeLog table transfer to History but when new data come in RealTimeLog table old data not changed by new one means OutTime data is not changed with new data from RealTimeLog. insert into History (UserID,UserName,LogDate, [InTime], [OutTime]) SELECT UserID,UserName,[LogDate],CONV...