query

Top 10 collection completion - a monster in-query formula in MySQL?

I've got the following tables: User Basic Data (unique) [userid] [name] [etc] User Collection (one to one) [userid] [game] User Recorded Plays (many to many) [userid] [game] [scenario] [etc] Game Basic Data (unique) [game] [total_scenarios] I would like to output a table that shows the collection play completion percentage fo...

Problem with Date Query - sql server 2008

hi i have this date's & Time's: date1: 10/04/2010 - Time: 08:09 date2: 11/04/2010 - Time: 08:14 i need to show all the date's between 10/04/2010 time 06:00 and 11/04/2010 time 6:00 i write this: select * from MyTbl where ((Tdate BETWEEN '20100410' AND '20100411') and (Ttime BETWEEN '06:00' and '06:00')) but i get empty table than...

What is wrong with mysql query?

I use the following mysql query, DELIMITER $$ DROP PROCEDURE IF EXISTS `allied`.`aboutus_delete`$$ CREATE DEFINER=`allied`@`%` PROCEDURE `aboutus_delete`( IN p_Id int(11) ) BEGIN if exists( select aboutUsId from aboutus where aboutUsId=p_id and isDeleted=0 ) ...

SQL query: Delete a entry which is not present in a join table?

Hi, I’m going to delete all users which has no subscription but I seem to run into problems each time I try to detect the users. My schemas look like this: Users = {userid, name} Subscriptionoffering = {userid, subscriptionname} Now, what I’m going to do is to delete all users in the user table there has a count of zero in the subscr...

Calling methods or functions with Jquery

So I can call a php page using jquery $.ajax({ type: "GET", url: "refresh_news_image.php", data: "name=" + name, success: function(html) { alert(html) $('div.imageHolder').html(html); } }); However this getting a bit messy, I have a few .php files that only really preform very simple tas...

nHibernate query looking for the related object's related object

I have an nHibernate querie issue that looks quite straight forward, but I can't seem to get my head around it! I am creating some simple example classes to illustrate my problem: public class Car { public int Id { get; set; } public IList<Interior> InteriorParts { get; set; } } public class Interior { public int Id { get;...

Problem in HQL query

I written a query in my sql like this: "select * from table_name order by col_name = 101 desc " Which is working perfectly fine in mysql but when I tried to convert this query into HQl query then it is throwing an exception.So can anyone suggest me that how to write HQL query for the above SQL query. ...

Constant Function in SQL Server (slow view that uses a function)

Hi, I have coded a view that relies on a scalar function value for one if its join conditions. The query plan is conservatively expecting that the function result could change between executions when the function is constant (at least for each complete query). The result changes once a day or so. Because of the huge number of rows the ...

Zend Framework query taking too long to execute

I have a query to check how many unique votes each photo has in a photo contest. In my Votes.php model I have this query, which for 200 photos is taking around 15 minutes to complete: public function getVotes() { $itemsTable = new Photocontest_Model_Photos(); $items=$itemsTable->fetchAll(); ...

How to cache queries in Rails across multiple requests

I want to cache query results so that the same results are fetched "for more than one request" till i invalidate the cache. For instance, I want to render a sidebar which has all the pages of a book, much like the index of a book. As i want to show it on every page of the book, I have to load it on every request. I can cache the rendered...

LogParser for Java

I just read this post and i wonder if there is something like this for querying jboss log file. ...

Iterating result of Select Query

Hi experts, I have a question related to select query. here i am explaining down below. i have a table with the following data **Column1(Primary Key) Column2 Column3** ------ --------- -------------- 1 C 2 C 3 Nul...

Subsonic 3.0 UPDATE, multiple conditions

db.Update<Luna.Record.TB_ITEM>().Set( x => x.ITEM_DURABILITY == Convert.ToInt32(quantity)) .Where(x => x.ITEM_POSITION == Convert.ToInt32(position)) .Execute(); How will I add an AND clause this is how it looks like in plain SQL: UPDATE TB_ITEM SET ITEM_DURABITLITY=@quantity WHERE ...

Is it poor practice to build an SQL query using WHERE 1=1 AND ...

I'm writing a PHP script that builds an SQL query by concatenating the string and adding conditions to the WHERE clause as needed. Would it be better practice to use WHERE 1=1 so that the first condition is satisfied and the script can just concatenate an AND x = 'y' to the query, or should I write the extra code to check if a clause ha...

How to SUM() from an offset through the end of the table?

If SELECT SUM(amount) FROM transactions ORDER BY order LIMIT 0, 50 sums the amount field for the first 50 records in a table, how do a sum all records after the first 50? In other words, I'd like to do something like SELECT SUM(amount) from transactions ORDER BY order LIMIT 50, *, but that doesn't work. ...

Why doesn't this CompiledQuery give a performance improvement?

I am trying to speed up an often used query. Using a CompiledQuery seemed to be the answer. But when I tried the compiled version, there was no difference in performance between the compiled and non-compiled versions. Can someone please tell me why using Queries.FindTradeByTradeTagCompiled is not faster than using Queries.FindTradeByTr...

Shouldn't prepared statements be much faster?

$s = explode (" ", microtime()); $s = $s[0]+$s[1]; $con = mysqli_connect ('localhost', 'test', 'pass', 'db') or die('Err'); for ($i=0; $i<1000; $i++) { $stmt = $con -> prepare( " SELECT MAX(id) AS max_id , MIN(id) AS min_id FROM tb "); $stmt -> execute(); $stmt->bind_result($M,$m); $stmt->free_result(); $rand = mt_rand( $m , ...

How do views reduce code duplication?

Hi! I read something like this about db views: Views are incredibly powerful and useful for one reason that stands out above all the other very good reasons. They reduce code duplication. That is, in most cases, the bottom line. If a query will be used in three or more places, then a view will drastically simplify your ...

MySQL inner join problem or other equal solution

Hello, For a few hours I was figuring out how to make an inner join these tables(tables are simplified for this question): Table message have these fields: | id | content | Table message_relation have these fields: | id | message_id | sender_id | receiver_id | Table user have these fields: | id | name | What I want to do with th...

mysql group by and count rows problem

hello let's say mysql is something like this select x,y from xx group by y i want to know how many rows that select will get, i tried to use count but it will n't return all results since i'm using group by. how to do that? Thanks ...