sql

How do I analyse time periods between records in SQL data without cursors?

The root problem: I have an application which has been running for several months now. Users have been reporting that it's been slowing down over time (so in May it was quicker than it is now). I need to get some evidence to support or refute this claim. I'm not interested in precise numbers (so I don't need to know that a login took ...

Row-wise IN BETWEEN comparison in a single SQL statement

Given the following tables: CREATE TABLE tree ( id serial NOT NULL, name character varying NOT NULL, type integer, lft integer NOT NULL, rgt integer NOT NULL ) CREATE TABLE item ( id serial NOT NULL, name character varying NOT NULL, tree_id integer CONSTRAINT fk_tree FOREIGN KEY (tree_id) REFERENCES ...

What is the correct way to backup and restore rollover databases in SQL Express

Hello, Recently I backuped up all of my database parts: mydb mydb_part_1 mydb_part_2 mydb_part_3 Each backup at different speeds. The smallest mydb backedup faster. Then in an absent minded moment, restored just mydb. The system seems to be working but what have I done and what is the best way to handle these roll-over databases? ...

insert values with select

I have two tables create table p ( x number, y number, z number ); create table q ( a number, b number, c number, d varchar2(20) ); I have inserted insert into p values('1','2','3'); now i need to insert into q selecting values from p with last field getting name like Table _name in table q values such tha...

How can I optimize this query?

I have the following query: SELECT `masters_tp`.*, `masters_cp`.`cp` as cp, `masters_cp`.`punti` as punti FROM (`masters_tp`) LEFT JOIN `masters_cp` ON `masters_cp`.`nickname` = `masters_tp`.`nickname` WHERE `masters_tp`.`stake` = 'report_A' AND `masters_cp`.`stake` = 'report_A' ORDER BY `masters_tp`.`tp` DESC, `masters_cp`.`punti` DESC...

what is the difference between GROUP BY and ORDER BY in sql

When do you use which in general? Examples are highly encouraged! I am referring so MySql, but can't image concept being different on another DBMS ...

Drupal - logic of the template.php file

Hi guys, I have spent a good proportion of time today looking into expanding a drupal site I inherited, convinced that the issues I face were down to my bespoke SQL query. I have since realised that the SQL is ok (checked it in PHPMYadmin and got it executing of sorts within the drupal website). So I am happy I am getting all the resul...

Finding Max and Min Times

I want to display max time and min time for a day in grid control using Visual Basic from a SQL Server database. My data currently looks like this: UserID UserName Date Time ------------------------------------------ 1 Shanks 30/1/2009 10:11:22 1 Shanks 30/1/2009 10:15:22 1 Shanks ...

Changing IN to EXISTS in SQL

I have the following query: select A,B from table1 where A in (select c from table 2) But, now I need to change this query and use exists instead of in, and it should give the same results. My tables look like the following: table1 table2 A B c ------ ----- 1 x 1 2 y ...

PHP MVC - how to pass data between different layers - objects or arrays

I always come to the same problem when implementing new data object that some web site will use. It seem to me naturaly to fill the object ... object: news news subobjects: mediaItems, user, category I usualy implement lazy loading of associated objects (lists of objects) and also have a static method to fill the news object data, med...

Understanding SQL REFERENCES

Recently I've asked a question about the best way to go to design a DB schema to support multiple types of users and interactions between them, one of the answers suggested that I use one table for each user type and Distributed Keys. The thing is the only databases I actively work with are MySQL and SQLite and I've always done this kin...

I need to upload images in asp to sql and then view them in asp

I am relatively new to sql and asp. My problem is that i need to be able to upload a number of image files, mainly jpgs, to a sql database database. Then i need to be able to display them as part of a catalogue. Ive searched around for a while and am struggling to find anything that seems to let me do this. Any help or guidance would b...

Use linq to get parent objects based on one of the property in a self referencing table.

Hello, I have a table called Quiz that have these fields id As Int created As DateTime header As Sring body As String fk_parent As int url As String All the items without parent key would be the question, and ones that have the parent key would be the answer. I am having the problem to get all the latest active questions (based both ...

Advantages and Disadvantages of NHibernate

What are the advantages/disadvantages of using NHibernate ? What kind of applications should be (& should not be) built using NHibernate ? ...

SQL Efficiency with Function

Hello, So I've got this database that helps organize information for academic conferences, but we need to know sometimes whether an item is "incomplete" - the rules behind what could make something incomplete are a bit complex, so I built them into a scalar function that just returns true if the item is complete and 0 otherwise. The pr...

Why do you create a View in a database?

When and Why does some one decide that they need to create a View in their database? Why not just run a normal stored procedure or select? ...

Is it possible to do string concatenation in a ColdFusion Query of Queries?

I'm familiar with this sort of syntax in SQL Server, to concatenate strings in my result set: SELECT 'foo' + bar AS SomeCol FROM SomeTable I would like to do something similar inside a ColdFusion Query of Queries: <cfquery name="qOptimize" dbtype="query"> select image_id AS imageId, '#variables.img_root#' + image_id + ...

How can I extract string ‘abc.com’ from a string http://[email protected] using sql?

How can I extract string ‘abc.com’ from a string http://[email protected] using sql? ...

sql complex tree rows

i have following function with a query. it works fine with integer id, but if the id is varchar (ID: Xewi3adc), then it dont work. well i dont know how to make it work yet, i been making lots of modifications, but i could'nt get it work. DROP FUNCTION IF EXISTS album_tree_connect; DELIMITER $$ CREATE FUNCTION album_tree_connect(value...

SQL setting dictating how floats are stored

Good day to all. I fond an odd difference between my test environment and my production environment. I have a table which stores data as a float. I run the following script on both with different results: insert into myTable(myFloat) select top 1 26.1295 as foo Select myFloat from myTable Server A = 26.1295 Server B = 26.129499435...