query

NHibernate select most recent record that meets criteria

Last night I started working on an NHibernate provider. I'm creating a criteria that several records will match, however I only want to return the most recent record (the record with the largest Id). I thought UniqueResult() would do this it cannot be used if a list would be returned otherwise. I could theoretically select the full li...

PDO: check tags presence in db and then insert

Hi, I'm working with PDO connection for mysql and I'd like to have some opinion on a query I use to check if tags are present on the database, and to add it in the case it isn't. // the tags are allready processed in $tags array $check_stmt = $connection->prepare ("SELECT * FROM tags WHERE tag_name = :tag_name"); $save_stmt = $connect...

Determining what a word "is" - categorizing a token

Note: Edited for clarification. Clarification: I'm writing a "bridge" between the user and a search engine, not a search engine. Part of my value add will be inferring the intent of a query. The intent of a tracking number, stock symbol, or address is fairly obvious. If I can categorise a query, then I can decide if the user even ne...

Blogger (Python) API: How do I retrieve a post by post ID?

Having previously obtained a post ID from a call to gdata.blogger.client.add_post()... post = client.add_post(...) post_id = post.get_post_id() ...how do I use that post id to retrieve the post in the future? I thought maybe gdata.blogger.client.Query would be the way to go, but this doesn't support post id as a query term. The exam...

how to write where condition in fql facebook using asp.net?

Hi all, I need to execute a fql using facebook dll in asp.net. The fql is ="select name, profile_url from user where name = 'suresh'". When I execute this i could not get the response . I am getting only empty string. string response = fbService.fql.query("select name, profile_url from user where name = 'suresh'"); but if i search by...

combine 2 query - sql server 2008 question

I have this query: select count (convert(varchar(50), TmpDate, 103 )),convert(varchar(50), TmpDate, 103 ) from MEN group by TmpDate order by TmpDate desc and I need to count how many rows it returns how I can combine select count (..... and query1 ? I need it in one query thanks in advance ...

LINQ to NHibernate can't get to children's children

I have entity A which has an IList of B called Bs and B has an IList of C called Cs. I want to search for all A's which have at least 5 C's in them. So I went and wrote using (var s = this._sessionFactory.OpenSession()) { IQueryable<A> q = s.Linq<A>(); // some code... if (range.Min.HasValue) q = ...

I cannot calculate a division in my SQL code

The following code works without problems: select donem, mekankodu, count(yayin_kodu) yc, SUM(CASE WHEN iade =0 THEN 1 ELSE 0 END) yys from ( select donem, bayi_adi, bayi_kodu, x.mekankodu, mekan_adi, mekan_tipi, yayin_kodu, yayin_adi, ...

SQL Query JOIN Performance

Hey all, I wanted to know what is better performance-wise: to put the conditions in the JOIN? (x JOIN y on x.hi = y.hi AND ....) or maybe to put it under the WHERE, and leave the JOIN only with the crossing condition. thanks folks ...

Need MySQL Queries to delete WordPress Posts and Post Meta more than X Days Old

I run a blog where the community can post time-sensitive community links (sports scores and such). After a certain time, those posts are no longer useful, so I want to delete them in batch via a MySQL query, but I don't know how. I imagine that getting rid of those posts entirely is more than just deleting from the wp_posts table, right?...

Ruby on Rails query by datetime range ( last 24, 48, etc... hours )

I'm trying to build a query that will search for recent entries based on column 'last_login_at'. This is a datetime field with time zone (i.e. Time.zone.now) When I execute User.find(:all, :conditions => ["last_login_at < ?", 24.hours.ago]) I get nothing. Alternatively I can define today as Time.zone.today and yesterday as Time.zone...

mySQL query, for discrete results limited and ordered by a joined column

I have two tables User id name Result id user_id score created_at Every hour a cron job runs and puts data in the result table for each user - assigning them a score based on some external variable parameters. So the Result table contains many records for each user. I want to retreive a 'top ten' users at any given poin...

mysql query optimization

Hello, This is the table structure: for_id from_id for_folder from_folder deleted The number 2 represents my ID and this is the query: SELECT * FROM poruke_konverzacija WHERE ( ( for_id =2 AND for_folder = "inbox" ) OR ( from_id =2 AND from_folder = "inbox" ) ) AND deleted !=2 I have near 500k records on that table and when i run...

MySql Query: ordering by two fields in two tables

Hi everybody, I have two tables storing members data members: id, field1, field2 and field3... members_extra: memberId, someExtraField1 and someExtraField2 members_extra.memberId is a Foreign Key referencing members.id 'members_extra' may or may not have related rows for rows in 'members' let's say: I have 1000 members in 'members...

Are integer queries on MySQL DATE or TIME columns slow?

Is it more efficient for me to store dates as INTs and convert to and fro a string representation such as "2010-01-30" or is it alright to store dates as DATE when needing to perform very frequent integer queries such as WHERE Date < 20100130... Are dates internally stored as strings or integers? ...

[SQL] Is it possible to update a fields value with the value of the field in the previous row?

I have a table from which I would like the update the value of a certain colum of fields. Basicly moving one value down and those under it should inherit the previous value of the one about them. I wonder if this action is possible using a single SQL query. My table: CREATE TABLE `menu` ( `slot_index` int(2) NOT NULL, `language_...

Trouble with MySQL UPDATE syntax with the module mysqldb in Python

I am attempting to execute the following query via the mysqldb module in python: for i in self.p.parameter_type: cursor.execute("""UPDATE parameters SET %s = %s WHERE parameter_set_name = %s""" % (i, float(getattr(self.p, i)), self.list_box_parameter.GetStringSelection())) I keep getting the error: "Unknown column 'M...

PHP SQL counting number of matches for query

How would i go about counting the number of rows that match two variables? I have a table called: users and fields called: username & referral I have another table called: comments and fields called: *comment_username* This is the situation, I need to fetch the number of referrals with at least 10 comments (rows in the comments' tab...

need help with sql server 2008 query - max from select

hi i have this query and i need to get the max value of number and the city how to do it ? select city,count(id) as number from men group by city order by number desc thank's in advance ...

What's the most efficient way to get the horizontal average in a MySQL query?

I have the following MySQL-table Id | One | Two | Three ---------------------------- 1 | 10 | 30 | 20 2 | 50 | 60 | 20 3 | 60 | NULL | 40 Edit: Of course the table doesn't need to be NULL by default, but I don't want it to affect the average (so the average is calculated as 50 and not 33,33). I want tha...