query

query language for graph sets: data modeling question

Hello. Suppose I have a set of directed graphs. I need to query those graphs. I would like to get a feeling for my best choice for the graph modeling task. So far I have these options, but please don't hesitate to suggest others: Proprietary implementation (matrix) and graph traversal algorithms. RDBM and SQL option (too space consu...

Retrieving widget data with MySQL query in WordPress

I've built up multiple dynamic sidebars for front page item manipulation. Each sidebar contains a Text widget, and I want to retrieve each widget's content (according to widget ID) from wp_options. Basically, the structure is dbName -> wp_options -> option_id #92 contains the following: a:9:{i:2;a:0:{}i:3;a:3: {s:5:"title";s:0:"";s:4:...

MySQL Query Select using sub-select takes too long

I noticed something strange while executing a select from 2 tables: SELECT * FROM table_1 WHERE id IN ( SELECT id_element FROM table_2 WHERE column_2=3103); This query took approximatively 242 seconds. But when I executed the subquery SELECT id_element FROM table_2 WHERE column_2=3103 it took less than 0.002s (and resulted 2 ...

help with sql query

hi i have 2 tables: Mal: IdNum,Name Trap: IdNum,Tdate,Name input: from Tdate to Tdate and Name i need all the IdNum that in Mal but not in Trap and the input condition i work on oracle 10g thank's in advance ...

MySQL: When updating, ignore empty strings

I know how to do this using PHP, but I was wondering if MySQL provides for a simpler solution. UPDATE users SET fname = 'badooka', lname = '' WHERE user_id='322'; If a value is empty (lname, in this particular case), how do I ignore it instead of overwriting the original with an empty string? ...

what the difference between not in - and - not exists in oracle query ?

hi what the difference between not in - and - not exists in oracle query ? when i use not in and when i use not exist ? thank's in advance ...

How to get SQL queries for each user where env is production

Dear all, I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: module SqlHunter class ActiveRecord::ConnectionAdapters::AbstractAdapter @@queries = [] cattr_accessor :queri...

SQL Query NOT Between Two Dates

Hello all, I need some help with SQL Query. I am trying to select all records from table test_table which would not fit between two dates '2009-12-15' and '2010-01-02'. This is my table structure: `start_date` date NOT NULL default '0000-00-00', `end_date` date NOT NULL default '0000-00-00' ----------------------------- **The foll...

SUM/GROUP performance and the Primary Key

I have a table myTable with myGuid (uniqueidentifier), myValues (float), myGroup (integer) and a bunch of other fields which are not important right now. I want to do something as simple as: SELECT SUM(myValues) FROM myTable WHERE myGuid IN (SELECT * FROM ##test) GROUP BY myGroup ##test is just a temporary table with a single fiel...

ONE TO ONE LEFT OUTER JOIN

Hi everybody, I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, but there exists only ONE record that match that condition, so when it found its pair on B, it must stop and continue with th...

PostgreSQL , Select from 2 tables, but only the latest element from table 2

Hey, I have 2 tables in PostgreSql: 1 - documents: id, title 2 - updates: id, document_id, date and some data: documents: | 1 | Test Title | updates: | 1 | 1 | 2006-01-01 | | 2 | 1 | 2007-01-01 | | 3 | 1 | 2008-01-01 | So All updates are pointing to the same document, but all with different dates for the updates. What I am try...

What is a batch?

In Transact-SQL, a batch is a set of SQL statements submitted together and executed as a group, one after the other. Batches can be stored in command files. Is an *.sql file containing several SQL statements considered a batch? What else do we consider a batch? ...

The Return statement

Hi Assuming A.sql contains the following code, then second Select query won’t be executed due to Return statement: select * from Films; return; select * from Films; If A.sql was called inside a stored procedure SP1 or batch B1, then RETURN would transfer control back to SP1 or B1, respectively. But assuming A.sql isn’t called f...

Prevent Access screwing up queries it can't understand when switching to design mode

Coming back to Access after a long time doing other stuff, there is one thing that really bugs me, which is that if you unwittingly open a query in Design mode, where the designer can't represent the sql (even if it's valid), the designer will 'correct' your query for you, and there is no undo... Is there a workaround for this - or an o...

Ordering of WHERE clauses for SQL Server

Can it make any difference to query optimisation to have WHERE clauses in a different order for SQL Server? For example, would the query plan for this: select * from table where col1 = @var1 and col2 = @var2 be different from this?: select * from table where col2 = @var2 and col1 = @var1 Of course this is a contrived example, and ...

SQL count exposure of life time by age

Hi all (Using SQL Server 2008) I need some help visualizing a solution. Let's say I have the following simple table for members of a pension scheme: [Date of Birth] [Date Joined] [Date Left] 1970/06/1 2003/01/01 2007/03/01 I need to calculate the number of lives in each age group from 2000 to 2009. NOT...

Can one turn visual studio's 'smart' sql query assistant off?

When creating this query in the SQL querybuilder window in visual studio (2008): UPDATE outgoing_messages SET readstatus = 5 FROM outgoing_messages INNER JOIN connections ON outgoing_messages.connectionid = connections.connectionid WHERE (outgoing_messages.msgreference = '1...

My VIEW in MySQL its not working.

Hello all, i play whit CREATE VIEW's in MySQL 5, now i have a troble, how can i make sure when i use this code. SELECT * FROM view_shop_invoicer_list WHERE accept_date >= '2009-10-16 00:00:00' AND accept_date <= '2009-10-31 23:59:59' AND shopid = [SHOPID]; my VIEW look like this, down here, and it will not take ...

MS Access, Pass through query with complex criteria. Criteria include Select statments and vba functions.

I currently have multiple queries that query data from a few tables linked through ODBC, and some temporary tables that are edited through the user interface. I have complex criteria in my queries such as: SELECT * from ThingsData WHERE (Thing In(SELECT Thing from ListOfThings) AND getThingFlag() = True); In this case Thing is a field...

Database table with 3.5 million entries - how can we improve performance?

We have a MySQL table with about 3.5 million IP entries. The structure: CREATE TABLE IF NOT EXISTS `geoip_blocks` ( `uid` int(11) NOT NULL auto_increment, `pid` int(11) NOT NULL, `startipnum` int(12) unsigned NOT NULL, `endipnum` int(12) unsigned NOT NULL, `locid` int(11) NOT NULL, PRIMARY KEY (`uid`), KEY `startipnum`...