sql

difference between given dates

I have a sqlce database table that I am entering data every day. Date No Meter_1 Meter_2 Meter_3 12-05-2010 1 1234 3456 4567 12-05-2010 2 3423 4567 0987 13-05-2010 1 2345 7654 7654 13-05-2010 2 7676 8765 5643 14-05-2010 1 ...

long oracle query

Hi there, I've got really long and complicated query(Oracle 10g). It contains about ten select subqueries. The query works but it's too long. Should I somehow divide this query? I mean is there some standard how long/complicated could sql query be. The query works but it doesn't seem to me like the best solution. For example one subquery...

sql queries in code files

I am a little bit reluctant when it comes to mixing SQL queries with my code ... I tend to not like it aesthetically. I was wondering whether there's a better way of storing them, without having to mix them with the code. What I've found until now: Use an ORM and you don't have to worry about storing full SQL strings - this is not an o...

One table, two column MYSQL query question

Consider a MYSQL table called "comments" with 2 fields, "hostname" and "username". How do I return a list sorted by hostname where the 2nd column is a list of usernames associated with each hostname? I can see how to do this with a scripting language like py, but is it possible as a standard sql qurey? If I do "SELECT hostname,count(d...

How to retrieve selected row from datagridview and store in DataTable

I have Datagridview .. selected a row .i want that row to be added to my list in other form ...

SWITCH with LIKE inside SELECT query in MySQL-Resolved

I have this Tags table CREATE TABLE IF NOT EXISTS `Tags` ( `id_tag` int(10) unsigned NOT NULL auto_increment, `tag` varchar(255) default NULL, PRIMARY KEY (`id_tag`), UNIQUE KEY `tag` (`tag`), KEY `id_tag` (`id_tag`), KEY `tag_2` (`tag`), KEY `tag_3` (`tag`), KEY `tag_4` (`tag`) ) ENGINE=InnoDB DEFAULT CHARSET=l...

Oracle sql function question

How to display the details of employee whose name contains the same characters at the start and end position of their name? ...

How to select rows based on values in other rows

I have a database full of sports results. I'd like to select some results based on some characteristics of the previous results. Here's the database structure: CREATE TABLE `results` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `date` DATETIME NOT NULL , `home_score` INT NOT NULL , `away_score` INT NOT NULL , `ho...

Group and select last insert in a table

Hi, I've a table to save some file with a simple versionning system like : ID | FILENAME | CONTENT | DATE 1 | index.php | Content of index.php v1 | timestamp 2 | main.css| Some CSS content | timestamp 3 | index.php | Content of index.php v2 | timestamp I need to code a SQL request to find in this table the last inserted content of ea...

Mysql: how to select groups having certain values?

Hello. Say there is such table: mysql> SELECT * FROM tags; +---------+--------+ | post_id | tag_id | +---------+--------+ | 1 | 2 | | 1 | 3 | | 1 | 1 | | 2 | 1 | | 2 | 2 | +---------+--------+ 5 rows in set (0.00 sec) Field names are pretty self-explanatory. I want to select post_...

sql server 2008 LIKE performance

I've noticed that the first sql statement with LIKE on a large table runs very slowly (around 20 minutes) but every subsequent one very very fast (a few seconds), even if the strings searched for are completely different from the initial one (the first string 'ability%', the second 'su_mit%') Does sql server store the results of table ...

eclipse java how to had sqlite-jdbc-(VERSION).jar into my project and use it

my scenario : on my work on android sqlite i noticed I need to build the sql data base outside the app in java therfor as one who knows nothing about how to install *.jar files i google it all the example for how to install it weren't relevant for my situation where my platform is eclipse in windows 7 . i would someone to instract me...

using a same column in place of another

I have a table which have 3 fields: id, name, reporting to which have other ids: ID NAME REPORT ------------------- 1 asd 3 2 vv 1 3 dv 2 I want name to be printed in place of ids in the report column: ID NAME REPORT ------------------- 1 asd dv 2 vv asd 3 dv vv Can somebod...

Error 360: Cannot modify table or view used in subquery.

INFORMIX-SE 7.32: I'm getting error 360 when I try to execute the following statement: update transaction set transaction.colx = (select tab1.cola from tab1) where transaction.num = (select max(transaction.num) from transaction) and transaction.colx IS NULL; Any ideas? ...

SQL: Performance comparison for exclusion (Join vs Not in)

Hello, I am curious on the most efficient way to query exclusion on sql. E.g. There are 2 tables (tableA and tableB) which can be joined on 1 column (col1). I want to display the data of tableA for all the rows which col1 does not exist in tableB. (So, in other words, tableB contains a subset of col1 of tableA. And I want to display t...

Selecting a group of names

I am struggling with a query in SQL Server 2005-2008 There are 15 participants in a tournament. Every day, 7 random participants are chosen. Out of the 7, one is the teamleader. The condition is that if a person has become a teamleader once, he cannot become again till all the others (rest 14) have got their chances. How can i write ...

SQL, How to change column in SQL table without breaking other dependencies?

I'm sure this might be quite common query but couldn't find good answer as for now. Here is my question: I've got a table named Contacts with varchar column Title. Now in the middle of development I want to replace field Title with TitleID which is foreign key to ContactTitles table. At the moment table Contacts has over 60 dependencie...

can transaction be rolled back after its commited and connection is closed

finally { // Commit the transaction. sqlTran.Commit(); reader.Close(); reader.Dispose(); conn.Close(); conn.Dispose(); } i would like to give the user an option of opps! roll it back so its commited can it be rolled back? ...

I want to know if this query method is possible ?

I have this Query SELECT PaymentDetails_ID AS Pay_ID, Type, Description, Details, Due_Date, PaymentDetails_Cleared, Amount, Mode, (SELECT Bill_ID FROM Bill_Payment_Records WHERE (Payment_ID = Pay_ID)) AS Bill_No FROM Pa...

Connecting SQL 2008 from SQL 2005 Enterprise Manager

Is It Possible to connect SQL Server 2008 from SQL Server 2005 Enterprise Manager? I am getting below mentioned error while connecting An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow r...