query

Elixir/SQLAlchemy equivalent to SQL "LIKE" statement?

I'm using the MySQLicious type schema described here for a simple tagging system. I've read some alternative implementations of tagging schema in 4 different SO threads, and this suits my needs best. A collection of entries have the tags "apple banana orange" and "strawberry banana lemon", and I'm trying to find the Elixir/SQLAlchemy eq...

Sqlite LIMIT / OFFSET query doubt

Hello, I have simple question with Sqlite. What is the difference between this: Select * from Animals LIMIT 100 OFFSET 50 and Select * from Animals LIMIT 100,50 thanks in advance ...

SQLite Query: How to find out the Average of last X records for every person

Let's say I have two SQLite tables: Table Players id|name Table Scores id|player_id|score|timestamp What would an SQLite query looks like, if I want to calculate the average scores for every players, but only from 5 of their latest scores. I've a working query that only works to calculate the average from all scores (using GROUP BY ...

Select records for MySQL only once based on a column value

Hi all, I have a table that stores transaction information. Each transaction is has a unique (auto incremented) id column, a column with the customer's id number, a column called bill_paid which indicates if the transaction has been paid for by the customer with a yes or no, and a few other columns which hold other information not relev...

Optimizing Sqlite query for INDEX

Hello, I have a table of 320000 rows which contains lat/lon coordinate points. When a user selects a location my program gets the coordinates from the selected location and executes a query which brings all the points from the table that are near. This is done by calculating the distance between the selected point and each coordinate poi...

Querying Project Gutenberg catalog.rdf via SPARQL

Hello. I'm having difficulty structuring a SPARQL query for the Project Gutenberg catalog (available at Gutenberg Feeds toward the bottom of the page). I know it is a fundamental lack of understanding on my part of how SparQL/RDF/etc. actually work, conflating it with SQL, etc. But I've tried several tutorials, and I just can't quite ...

Hibernate setParamater a class

I am new to Hibernate. I want to create a public Object getById(Class class,long id) function. I tried creating query like: from :nameEntity where id= :id but I'm facing problems when setting parameter for nameEntity. Hibernate doesn't recognize it as a parameter. I used session.createQuery function. Could you please help me? ...

Transact Sql LEFT function weird output

select replace(stuff('123456',2,2,'ABCD'),'1',' ') select LEFT('ABCD456',4) select left(replace(stuff('123456',2,2,'ABCD'),'1',' '),4) Ok now the first select outputs 'ABCD456', the series of functions evaluates to that exactly the first parameter to the left function in the second select second select returns 'ABCD' as expected thir...

Query with multi tables

I have four tables: characters arena_team arena_table_member arena_team_stats. characters table has guid, name arena_team table has arenateamid, name, type arena_table_member table has guid(this is the same as in characters table), arenateamid arena_team_stats table has arenateamid, rating, wins, wins2, played How do I get the li...

Using CASE in Order By Clause

I have the following SQL: ALTER PROCEDURE [dbo].[SP_Products_GetList] @CatID int, @CatName int, @SortBy varchar(50), @SortType varchar(50) AS SELECT Products.ProductID, ProductName, MAX(Price) Price FROM Products INNER JOIN ProductCategory on Products.ProductID = ProductCategory.ProductID INNER JOIN ( ...

Running a query multiple times vs using a cookie

A question about query/database performance: I have a table that records how many “points” a user has earned. There is 1 row for every 1 point. When someone gains 20 points, 20 rows are inserted into the database. When someone looses 20 points, I will add a row with the value of “-1” in the database. Thus the number of points someo...

AppEngine query for None parent

I'm trying to find all object which have no parent (i.e. which were created with parent=None). Using M.all().filter("parent = ", None).fetch(100) doesn't bring any results, even though some objects certainly do have no parent. What am I doing wrong? ...

Various ways to query strings?

I'm working on an app that involves a lot of carefully designed strings. I'm in the process of designing the string format and for that I need to know what's possible and what's not when I'm querying the same data. Which ones of these are possible with MySQL? .. and how do I accomplish them? Results which contain this exact string -- ...

Get Objects from an ObjectSet by specifying a Range in EF

Hi all, I am trying out EF 4.0.I have an Employee Object and using EF I am getting the Employee ObjectSet by simply calling Context.Employees Now the above call will spit following sql query select * from Employees The above query works fine and I don't have any complains on it however as you know this will not be performant...

with index, returns different result.

Never seen this before. Running the same query, 1 forces an index. Without the index, the results are incorrect (in wrong order), with the index the results are in the correct order. Only problem with using the index is that its slower for some reason. Index is on comment_id and user_id without index: SELECT DISTINCT topic_id FROM comm...

Aggregate functions return wrong values when joining more tables

I want to display all customers and their addresses and the number and total sum of their orders. My query looks like this: select *, sum(o.tota), count(o.total) from customer c natural join orders o group by c.custId; which works fine. but if I add a new table to the query: select *, sum(o.tota), count(o.total) from customer c ...

Linq to XML, select all attributes and their values for a given node

I have an xml mapping file that looks something like this <colourMappings> <model name="modelX"> <mapping colour="White" configCode="1"></mapping> <mapping colour="Aluminium" configCode="2"></mapping> <mapping colour="Black" configCode="3"></mapping> <mapping colour="Blue" configCode="4"></mapping> ...

showposts VS posts_per_page. showposts works perfect but deprecated!

I'm unable to substitute posts_per_page with showposts in order to limit the number of posts returned in a list. When I use showposts, the resulting menu list is correctly displayed according to the number of posts I specify in the showposts limiter. However, when I use posts_per_page, the post limiter number appears to be irrelevant. Th...

MYSql query to concanate all the values in each row based on the comman same id matching.

Is there any way to concatenate the value in a field that matching with a comman field say userid. For eg if this is the table, UserID| Field1  |  Field2 1        | aaa    |   zzz 1        | bbb    |   yyy 1        | ccc    |   xxx i want it as a single row like-- UserID | Field1  |  Field2 1        | aaa,bbb,ccc,    |   zzz,yyy,x...

Slow Oracle query and USER_IO_WAIT_TIME

We have a slow query that has a low optimizer_cost value but a very high user_io_wait_time value. Does this just indicate that there is an I/O bottleneck? Should we allocate more memory to Oracle? Get faster disks? Note: the stats were gathered by querying V$SQL ...