query

SQL Query - Use Like only if no exact match exists?

I'm having an issue with a query that currently uses LEFT JOIN weblog_data AS pwd ON (pwd.field_id_41 != '' AND pwd.field_id_41 LIKE CONCAT('%', ewd.field_id_32, '%')) however I'm discovering that I need it to only use that if there is no exact match first. What's happening is that the query is double dipping due to the use of LIKE, ...

How to programmatically make a Query in MS Access default to landscape when printed

How can I programmatically make a query in MS Access default to landscape when printed, specifically when viewing it as a PivotChart? I'm currently attempting this in MS Access 2003, but would like to see a solution for any version. ...

SQL Text Searching, AND Ordering

I have a query: SELECT * FROM Items WHERE column LIKE '%foo%' OR column LIKE '%bar%' how do I order the results? lets say I have rows that match 'foo' and rows that match 'bar' but I also have a row with 'foobar' how do I order the returned rows so that the first results are the ones that matched more LIKEs? Thanks ...

How do I return random numbers as a column in SQL Server 2005?

I'm running a SQL query on SQL Server 2005, and in addition to 2 columns being queried from the database, I'd also like to return 1 column of random numbers along with them. I tried this: select column1, column2, floor(rand() * 10000) as column3 from table1 ...which kinda works, but the problem is that this query returns the same rand...

How do you create a parameterized query in MS Access 2003 and use other queries/forms to fill the parameters and obtain a resultset

I'd like to be able to create a parameterized query in MS Access 2003 and feed the values of certain form elements to that query and then get the corresponding resultset back and do some basic calculations with them. I'm coming up short in figuring out how to get the parameters of the query to be populated by the form elements. If I have...

Practical limit to length of SQL query (specifically MySQL)

Is it particularly bad to have a very, very large SQL query with lots of (potentially redundant) WHERE clauses? For example, here's a query I've generated from my web application with everything turned off, which should be the largest possible query for this program to generate: SELECT * FROM 4e_magic_items INNER JOIN 4e_magic_item_lev...

How can I make MS Access Query Parameters Optional?

I have a query that I would like to filter in different ways at different times. The way I have done this right now by placing parameters in the criteria field of the relevant query fields, however there are many cases in which I do not want to filter on a given field but only on the other fields. Is there any way in which a wildcard o...

NDepend CQL Count Query

I want to query a table of public methods of a specific class and a count of each methods usage in NDepend CQL. Currently query looks like this: SELECT METHODS FROM TYPES "AE.DataAccess.DBHelper" WHERE IsPublic Is it possible to aggregate queries in CQL? ...

Count image similarity on GPU [OpenGL/OcclusionQuery]

OpenGL. Let's say I've drawn one image and then the second one using XOR. Now I've got black buffer with non-black pixels somewhere, I've read that I can use shaders to count black [ rgb(0,0,0) ] pixels ON GPU? I've also read that it has to do something with OcclusionQuery. http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_...

SQL Query Help: Transforming Dates In A Non-Trivial Way

I have a table with a "Date" column, and I would like to do a query that does the following: If the date is a Monday, Tuesday, Wednesday, or Thursday, the displayed date should be shifted up by 1 day, as in DATEADD(day, 1, [Date]) On the other hand, if it is a Friday, the displayed date should be incremented by 3 days (i.e. so it becom...

SQL Query Help: Selecting Rows That Appear A Certain Number Of Times

I have a table with a "Date" column. Each Date may appear multiple times. How do I select only the dates that appear < k number of times? ...

Union and Intersect in Django

class Tag(models.Model): name = models.CharField(maxlength=100) class Blog(models.Model): name = models.CharField(maxlength=100) tags = models.ManyToManyField(Tag) Simple models just to ask my question. I wonder how can i query blogs using tags in two different ways. Blog entries that are tagged with "tag1" or "tag2": Blog.o...

Binding TRANSFORM query in Access to a report

Whats the best way to bind variable column names to a report field in Access when using a crosstab query? ...

Optimize SQL query on large-ish table

First of all, this question regards MySQL 3.23.58, so be advised. I have 2 tables with the following definition: Table A: id INT (primary), customer_id INT, offlineid INT Table B: id INT (primary), name VARCHAR(255) Now, table A contains in the range of 65k+ records, while table B contains ~40 records. In addition to the 2 primary k...

How do I select the Count(*) of an nHibernate Subquery's results

I need to do the following for the purposes of paging a query in nHibernate: Select count(*) from (Select e.ID,e.Name from Object as e where...) I have tried the following, select count(*) from Object e where e = (Select distinct e.ID,e.Name from ...) and I get an nHibernate Exception saying I cannot convert Object to int32. Any...

Selecting values grouped to a specific identifer

I have an application that tracks high scores in a game. I have a user_scores table that maps a user_id to a score. I need to return the 5 highest scores, but only 1 high score for any specific user. So if user X has the 5 highest scores on a purely numerical basis, I simply return the highest one and then the next 4 user scores. I ...

Row numbers for a query in informix

i am using informix database, i want a query which you could also generate a row number along with the query Like select row_number(),firstName,lastName from students; row_number(),firstName,lastName 1 john mathew 2 ricky pointing 3 sachin tendulkar here firstName,lastName are from Database , where as row number is genera...

As System in Sqlplus, how do I query another user's table?

According to select name from system_privilege_map System has been granted: SELECT ANY TABLE (and lots of other * ANY TABLES) Plainly running SQL>select * from the_table; select * from the_table; * ERROR at line 1: ORA-00942: table or view does not exist nets the given response. I can log in as that user and run the s...

How can I do the equivalent of "SHOW TABLES" in T-SQL?

I would like to do a lookup of tables in my SQL Server 2005 Express database based on table name. In MySQL I would use 'SHOW TABLES LIKE "Datasheet%"', but in T-SQL this throws an error (it tries to look for a SHOW stored procedure and fails). Is this possible, and if so, how? ...

Many to many table queries

I have a many to many index table, and I want to do an include/exclude type query on it. fid is really a integer index, but here as letters for easier understanding. Here's a sample table : table t eid | fid ----+---- 1 | A 1 | B 1 | C 2 | B 2 | C 3 | A 3 | C 4 | A 4 | B 5 | B Here are some sample queries I want...