query

Delete duplicate rows (don't delete all duplicate)

I am using postgres. I want to delete Duplicate rows. The condition is that , 1 copy from the set of duplicate rows would not be deleted. i.e : if there are 5 duplicate records then 4 of them will be deleted. ...

Asp.Net Query String

I am using Querystring to pass values from one page to other. I am tring to implement encoding and decoding using the Server.UrlDecode and urlEncode. Query string returns a null value, but I can check the values are been sent in URL. The two pages are: QueryString.aspx protected void Page_Load(object sender, EventArgs e) { } protec...

How to use index efficienty in mysql query

Hi: My db is running on mysql v5.x. I have a table T1 with 5 columns and column C1 is the primary key. C1 is of type varchar(20). It contains about 2000 rows with values like: fxg axt3 tru56 and so on.. Now my application's job is to read input data and find if the input data has a starting pattern similar to that found in column C1...

Optimising a trivial MySQL query to get rid of filesort

Hi, I've got a trivial mysql query which isn't liked by the server really: SELECT zone_id, SUM(inc_sec) AS voucher_used FROM cdr_bill_2010_09 WHERE cust_id = 1234 AND voucher_id = 'XXXXXX' GROUP BY zone_id Now this should be really quick (and usually is) since there are indexes on both cust_id and voucher_id (voucher_id is chosen)...

Where to put object-oriented queries in a layered architecture?

Given: You have an architecture with the layers presentation, business and data. You are applying domain-driven design. You are using an object-relational mapper that lets you create object-oriented queries (e.g., NHibernate which lets you create HQL queries). Question: Into which layer should you put the object-oriented queries? M...

nested LINQ XML subquery not displaying values from root query in asp.net listview?

var subfacets = from l in facets.Descendants("Facet") let FacetName = l.Attribute("Name").Value let DisplayedFacetAttr = l.Attribute("DisplayedName") select new { DisplayedFacetName = (DisplayedFacetAttr != null) ? DisplayedFac...

two way joins mysql query

message table id user_id| message 1 1 | this is my cruel message 2 1 | this is my happy message 3 2 | this is happy messgae message_tags table id message_id| tags 1 2 | happy 2 3 | happy what i want to acess all the messages that have the the tag happy, how would construct...

Lucene Numeric range query doesn't return all of the hits I expect.

I have a set of documents that all have a "timestamp" field which is stored as a long integer number. The field is indexed in my Lucene index as a number using NumericField with a precision step of 8: NumericField("timestamp", 8). This is done so I can do numeric range queries to retrieve all documents that fall within a specific time ...

TSQL stored procedure and XQuery?

Hello, I want to write a stored procedure that queries XML files after I have input a certain string pattern to look for. I'm already stuck at the input parameters, consider the following XML-document. <root> <container> <element>A</element> <option>1</option> </container> <container> <element>B</element> ...

MySQL: escape space from query

Is there a way using MySQL, to query a value containing a space, but as some sort of escape character? It's for an instant search engine I'm building (I'm trying to incorporate special search strings such as quotes to search for exact string). cheers ...

SQL Alternative to Like to return exact matches (ie. ?

I need this to return an exact match while still being able to use the wild card. So when searching for 'carb' i want to return a value such as 'Racing Carb' but i do not want to return a value such as 'Racing Carburetor' This is what I have now... SELECT I.SKU, I.[Description] FROM Inventory AS I INNER JOIN MisspelledWords AS ...

how can i change the pattern in php?

i got this pattern for searching purpose for mysql from third party javascript. im assuming its html pattern, which can be converted, anyone have any idea on this? pattern A%5B%D9%8B-%D9%93%D9%B0%5D*L%5B%D9%8B-%D9%93%D9%B0%5D*L%5B%D9%8B-%D9%93%D9%B0%5D* ...

Help with querying a many to many table in mysql

I am trying to get a list of product id's that do not have certain colors (database is mysql) Here are my tables: product +------------+-------------+ | product_id | description | +------------+-------------+ | 1 | Widget 1 | | 2 | Widget 2 | | 3 | Widget 3 | | 4 | Widget 4 | | 5...

Merge two results in a MySQL query if the records are related by a field value

We have a products table. Users can create new products as copies of existing products. Instead of simply duplicating this data, we're thinking in order to minimize database size, we would store only the differences from the "parent" product. (were talking thousands of products) My thinking is that, for each new "child" product, we cre...

Query to select tables with similar column values

Continuing to my subject "http://stackoverflow.com/questions/3767000/invalid-column-name-though-its-there" I wanna write a query that selects tables that has the values of the EntityId and DataclassId columns as identical values (skipping the nulls of course) Here is an example of my DB Table_1 ID Sequence Type Heigh Weight ...

How to find User Stories with open bugs?

Actually I would like to have a query that finds all User Stories, whose all tasks and bugs are closed. The problem is that bugs are not connected directly to the user story but only to the test case, and the test case is connected to the user story. Another problem is that test cases link to user stories and are not children of them. W...

MySQL export query as insert statements

Hi, I have two mysql tables which both have a typeID in common. I am wanting to select everything from these two tables with the same typeID, query below: SELECT ta.requiredTypeID, ta.typeID, ta.quantity FROM `invtypes` as t, `typeactivitymaterials` as ta WHERE volume > 0 AND t.typeID = ta.typeID; This gives me the correct res...

How to change time part of a datetime value with doctrine?

I need to change the time part of a datetime in a database. What I got is in the database: '2010-01-01 01:00:00' I need to update this to '2010-01-01 03:00:00' Only thing I have is '03:00:00' As I'm using doctrine I could iterate through all objects but this would decrease the perfomance. So what I tried was: $q = Doctrine_Query::crea...

What are best practices for database queries?

Hi, I would like to know what are best practices for database queries. I am using C#, mysql database. I have one application in which I had hardcoded all the database queries. Now client has modified database structure. So I have to again modify those queries and as all the queries are inside code, I need to test application, build it...

WPF Datagrid: Rowfilter for Lists/Collections

I recently migrated all my Datatables to List(Of), and bind it using .ItemSource. This works perfectly, but I run into a problem. Previously, I could filter the rows with SQL-like statements like this: Dim dk As DataView dk = DataGrid1.ItemsSource dk.RowFilter = "ID > 10" Now that I am using List(Of), i cannot use the rowfilter proper...