query

SQL query to insert the available slots into a table (avail) from booked slots table.

I want a sql query to insert the available slots into a table (avail) from booked slots table. I have two tables .I have a book table with bookstarttime and bookendtime columns .these are timestamp objects.I have another table with availstarttime and availendtime.these are also timestamp columns.I have to get the available slots left be...

SQL statement for evaluating multiple related tables

I have a Projects table, which lists the client info. Then I have four related jobs tables, for jobs within that project - Roofing, Siding, Gutters and Misc. The four tables have a projectID field to link them to the Projects table, and they all have a 'status' field. A project can have any combination of jobs. I want to be able to sele...

Using NHibernate to query with NOT IN in the WHERE clause

Take this query as an example: select * from publisher where id not in ( select publisher_id from record where year = 2008 and month = 4 ) Can anyone help me on how I could build and run this query using NHibernate? Assume that I have 2 classes: Publisher and Record. Thanks ...

MySQL query ordering data two ways

Hello, I am tracking page views within modules using the following table: id | page_id | user_id | session_id | created Every page is unique to a certain module; so page 14 only exists in module 2, for instance. I am trying to write a query that tells me when a viewing session began (GROUP BY session_id) for a particular module, but...

SQL equivalent of MS Access Partition function

I use Partition function lot for Report in MS Access 2003. I need equivalent of this function for MS SQL. Here is link about Partition function http://office.microsoft.com/en-us/access/HA012288921033.aspx (registration required) Thanks ...

MySQL Query optimisation

I am currently working on a website which needs some optimisations ... since the front page takes about 15-20 seconds to be loaded I thought that some optimisation would be nice. Here is one query that appeared on the MySQL slow query log: SELECT a.user,a.id FROM `profil_perso` pp INNER JOIN `acces` a ON pp.parrain = a.id INNER JOIN `a...

How am I supposed to query for a persisted object's property's subproperty in nhibernate?

I'm feeling dumb. public class Uber { public Foo Foo { get; set; } public Bar Bar { get; set; } } public class Foo { public string Name { get; set; } } ... var ubercharged = session.CreateCriteria(typeof(Uber)) .Add(Expression.Eq("Foo.Name", "somename")) .UniqueResult<Uber>(); return ubercharged; This throws a "could not r...

Why can't I see the results of the query in protege4?

I knew this might be a stupid question but I don't know the answer :) I am using protege4 I built my ontology and when I tried to use DL Query from the DL query tap in protege4 it executes fine and I get results. However, when I click "Add to ontology" to add my query to the ontology it adds it but without any query results!!! Why are...

Query with SUM using SubSonic

Hi, I'm new to Subsonic, I want to ask how to query with SUM? I know how to query for where condition such as below: Query qryCurOpcode = Station.CreateQuery() .WHERE("PRODLINE=PIECERATE_prodline") .AND("STATIONID=STNID") .AND("SHIFT=PIECERATE_shift"); IDataReader rdrCurOpcode = qryCurOpcode.ExecuteReader(); while (rdrCu...

Sum until certain point - MySql

How to do query and display the records until it reaches a certain number? Suppose you want to select student until the total sum of the student's money reaches 1000? Addition Student ID Student Name Student Money --------- ----------- -------------- 1 John 190 2 Jenny 290 ...

SQL query to extract text from a column and store it to a different column in the same record.

I need some help with a SQL query... I have a SQL table that holds in a column details of a form that has been submitted. I need to get a part of the text that is stored in that column and put it into a different column on the same row. The bit of text that I need to copy is always in the same position in the column. Any help would b...

How to list all tables or only those of a given database

You can get a list of databases using PRAGMA database_list or a list of tables in the "main" database using select name from sqlite_master where type='table' but as I just wrote, it only returns the tables from the "main" DB only, and I don't see a way to know which tables are in the other DBs. So how does one list the tables in t...

Why is MySQL Data Connector taking so much longer than MySQL Query Browser?

I have a very simple query (three where conditions; two equals, one between) from a single table and in MySQL Query Browser the query takes less than half a second to run, returning 8300 records. If I run the exact same query using the MySQL Data Connector (really just an OLEDB wrapper), it takes about 35 seconds. The engine being used ...

How to Pivot data from one table with SQL server 2005

Hello, I would like to create a query from a single table with the following columns. SEQNO is a unique key Name ID Amount Date JOBID SEQNO Mark 9 200 1/2/09 1001 1 Peter 3 300 1/2/09 1001 2 Steve 1 200 2/2/09 1001 3 Mark 9 200 3...

preserve primary key values in database

when i copy data from one table to another all the primary key values are resetted. is there a way to keep the values of the original table. in the original table the primary key values (int) are not continual (deleted rows) another table has all the values hardcoded thats why i need to keep the same values. ...

how to do a select max in django

I have a list of objects how can I run a query to give the max value of a field: I'm using this code: def get_best_argument(self): try: arg = self.argument_set.order_by('-rating')[0].details except IndexError: return 'no posts' return arg rating is an integer ...

Will View Increase The Performance?

I have Six tables which will joined in many queries.If a View created by joining all the tables will increase the performance?.Is there are any alternatives to increase the performance?. I am using oracle as the database and all the joined columns are indexed. ...

How to dynamically compose an OR query filter in Django?

From an example you can see a multiple OR query filter: Article.objects.filter(Q(pk=1) | Q(pk=2) | Q(pk=3)) For example, this results in: [<Article: Hello>, <Article: Goodbye>, <Article: Hello and goodbye>] However, I want to create this query filter from a list. How to do that? e.g. [1, 2, 3] -> Article.obj...

How to dynamically compose an OR query filter in Django?

From an example you can see a multiple OR query filter: Article.objects.filter(Q(pk=1) | Q(pk=2) | Q(pk=3)) For example, this results in: [<Article: Hello>, <Article: Goodbye>, <Article: Hello and goodbye>] However, I want to create this query filter from a list. How to do that? e.g. [1, 2, 3] -> Article.obj...

Does the number of columns returned affect the speed of a query?

If I have two queries SELECT Id, Forename, Surname FROM Person WHERE PersonName Like(‘%frank%’) And SELECT * FROM Person WHERE PersonName Like(‘%frank%’) Which query will run faster? Is the where clause / table joining the biggest factor, or the number of columns returned? I’m asking because I’m building a series of objects that m...