query

Is It possible to create recursive query in access?

I have a table Id ParentID jobName jobStatus The root ParentID is 0. Is it possible is Access to create a query to find a root for a given job. Database is mdb no linked tables. Access version is 2003. job can be in several grand child level. Any help would be appreciated. ...

size limit of a mysql query ruby/mysql

Hello everyone, I hope this is the appropriate place to ask my question. My mysql query currently looks like this @records = Record.find(:all, :select => "`records`.id, records.level as level, (SELECT (count( b.id ) + 1) FROM records as a, records as b WHERE a.id = records.id and b.skill > a.skill and b.created_at ='#{vandaag}' ...

Efficient SQL Query

Note: These are not homework problems. I am studying dbms on my own, hence these homework-like questions. Two tables : Teachers (teacher_id, teacher_name) Courses (teacher_id,course_id, course_name) In order to select teacher names who are not teaching any courses, there are two queries I can think of : mysql> explain select teach...

Mysql Max query

I have two tables : teachers (teacher_id,teacher_name) courses (teacher_id,course_id) And I need to display names of the teachers, teaching maximum number of courses : mysql> select teachers.teacher_name,tmp1.teacher_id,tmp1.cnt from (select max(tm p.cnt) as tmpMax from (select teacher_id,count(teacher_id) as cnt from courses g rou...

Calculating a T-SQL Query Parameter at Load Time

I'm trying to SELECT records out of an Events Database (with an EventDate field as Date) that have a EventDate that is in the current month. I have functions for calculating the first day of the month: public string GetFirstofMonth(DateTime dt) { int thisMonth = dt.Month; int thisYear = dt.Year; string firstOfMonth = thisMonth.ToStr...

Does the way you write sql queries affect performance?

say i have a table Id int Region int Name nvarchar select * from table1 where region = 1 and name = 'test' select * from table1 where name = 'test' and region = 1 will there be a difference in performance? assume no indexes is it the same with LINQ? ...

SQL Reader saying no values exist, query seems fine

I'm developing an ASP.NET application with VB, and using SQL Command and Connection in VB to grab the data for the page. I have both portions initialized as such: travelQuery.CommandText = "SELECT [StartLoc], [EndLoc],[TravelTime], [AvgSpeed], [Distance] FROM [TravelTimes] WHERE [TripNum] = '" + lblTrip.Text + "'" travelConnection.Conn...

How can I best extract transitions in a transactional table?

Hypothetical example: I have an SQL table that contains a billion or so transactions: | Cost | DateTime | | 1.00 | 2009-01-02 | | 2.00 | 2009-01-03 | | 2.00 | 2009-01-04 | | 3.00 | 2009-01-05 | | 1.00 | 2009-01-06 | ... What I want is to pair down the data so that I only see the cost transitions: | Cost | DateTime | | 1.00 | 2...

django foreignkey contains query

I have the following model class Command(models.Model): server = models.ForeignKey(Server) user_login = models.CharField(max_length=100) user_run = models.CharField(max_length=100) host = models.CharField(max_length=100) ip = models.CharField(max_length=100) session = models.CharField(max_length=100) command ...

How to I pull information from MySQL with PHP?

Hello, I am asking if it is not only possible to pull data from a MySQL table, but also display each row in either a table or a DIV, preferably a DIV. How would I do so? Table: ID |BodyText |Title | 1 |Hello World1 |Title1 | 2 |Hello World2 |Title2 | etc.. I'd like to put each row into a DIV that...

Weird SQL Server query problem

So I have this weird problem with an SQL Server stored procedure. Basically I have this long and complex procedure. Something like this: SELECT Table1.col1, Table2.col2, col3 FROM Table1 INNER JOIN Table2 Table2 INNER JOIN Table3 ----------------------- ----------------------- (Lots more joins) WHERE Table1.Col1 = db...

MySQL ON DUPLICATE KEY - last insert id?

I have the following query: INSERT INTO table (a) VALUES (0) ON DUPLICATE KEY UPDATE a=1 I want the ID of either the insert or the update. Usually I run a second query in order to get this as I believe insert_id() only returns the 'inserted' ID and not the updated ID. Is there a way to INSERT/UPDATE and retrieve the ID of the row wi...

SQL concatenating strings?

I have a query that takes input from the end user and compares it to 2 columns individually, and the two columns concatenated. SELECT f_name, l_name, (f_name + ' ' + l_name) AS full_name FROM users_table WHERE f_name = user-input OR l_name = user-input OR 'full_name' = user-input Excuse the massive syntax fail, but I assure you ...

Compare 2 values of different types inside of subquery

I am using a MS SQL db and I have 3 tables: 'base_info', 'messages', 'config' bases: ID Name NameNum ==================================== 1 Home 101 2 Castle 102 3 Car 103 messages: ID Signal RecBy HQ ============================ 111 120 Home 1 111 110 Castle 1 111 125 Car...

MySQL : selecting the X smallest values

Hi, Let be a table like this : CREATE TABLE `amoreAgentTST01` ( `moname` char(64) NOT NULL DEFAULT '', `updatetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `data` longblob, PRIMARY KEY (`moname`,`updatetime`) I have a query to find the oldest records for each distinct 'moname', but only if t...

Lazy evaluation of Oracle PL/SQL statements in SELECT clauses of SQL queries

I have a performance problem with an Oracle select statement that I use in a cursor. In the statement one of the terms in the SELECT clause is expensive to evaluate (it's a PL/SQL procedure call, which accesses the database quite heavily). The WHERE clause and ORDER BY clauses are straightforward, however. I expected that Oracle woul...

what's wrong with this sql query?

Okay I have two variables in PHP $username; $password; which are initialized to the data retrieved from $_POST variable :) I have this SQL query $sql = "SELECT * FROM users WHERE username = '" . $username . "' AND password = '" . $password . "')"; But this doesn't works and returns me nothing :( Can you instruct me into the right...

access db, select group by having max problem

in Access DB... I need to extract the itemcode / desc combination for each itemcode in the following table where the desc has been used most frequently. most frequently could possibly mean that there was only one version (see added record for pear) in the case of itemcode 777, I'll have to decide later which description version to use....

SQL strict enforce of order by a date column

I have a table(say TableA) with the following schema A(int) B(int) D (varchar) C(date) If I write the query select A, C from TableA where A >=0 order by A asc, B asc, D asc, C asc. The last row of the query will have the C date column which is largest ( I mean here the latest which is greater than all the other dates). I...

When trying to run an SQL query in delphi using a button click nothing happens!!

Hello, I am trying to run SQL queries using a button click in Delphi, the database is successfully connected everything compiles fine when i enter the query i.e. "Select * from StaffDetails" and then click on run expecting it to show me the results in the DBGrid nothing happens at all the code for the button is as follows procedu...