query

Complicated conditional SQL query

I'm not even sure if it's possible but I need it for my Access database. So I have following db structure : Now I need to perform a query that takes category_id from my product and do the magic : - let's say product belongs to console (category_id is in table Console) - from console_types take type_id, where category_id == category_id...

LINQ Query with dynamic where clause based on search criteria that is NOT part of the returned object

I have an AlumniRecords table with 60+ columns. I created an AlumniSearchResults class that only contains the handful of fields I need for display in a table of search results. This is an MVC2 app so I want to keep the objects clean (in other words, I don't want to pass the 60+ field object to my view). I am trying to build my AlumniS...

PHP <<< (multi-line handler?) question

I have some code as follows: $query = <<<QUERY SELECT * FROM names WHERE create_date > date('Y-m-d H:i:s'); QUERY How can I put the date('Y-m-d H:i:s') in there without breaking out of the <<< statement? ...

SQL 2005 indexed queries slower than unindexed queries

Adding a seemingly perfectly index is having an unexpectedly adverse affect on a query performance... -- [Data] has a predictable structure and a simple clustered index of the primary key: ALTER TABLE [dbo].[Data] ADD PRIMARY KEY CLUSTERED ( [ID] ) -- Joins on itself looking for a certain kind of "overlapping" records SELECT DISTINCT ...

Django query - join on the same table

i have a mini blog app, and a 'timeline' . there i want to be displayed all the posts from all the friends of a user, plus the posts of that user himself. For that, i have to make some kind of a 'join' between the results of two queries (queries on the same table) , so that the final result will be the combination of the user - posesor o...

javascript - query object graph?

Given an object like this: var obj = { first:{ second:{ third:'hi there' } } }; And a key like this "first.second.third" How can I get the value of the nested object "hi there"? I think maybe the Array.reduce function could help, but not sure. ...

if else query in mysql

i need an example of nested if-else condition in mysql query ...

Is there a way to optimize this update query?

I have a master table called "parent" and a related table called "childs" Now I run a query against the master table to update some values with the sum from the child table like this. UPDATE master m SET quantity1 = (SELECT SUM(quantity1) FROM childs c WHERE c.master_id = m.id), quantity2 = (SELECT SUM(quantity2) FROM childs c ...

django m2m how can i get m2m table elements in a view

i have a model using m2m feature: class Classroom(models.Model): user = models.ForeignKey(User, related_name = 'classroom_creator') classname = models.CharField(max_length=140, unique = True) date = models.DateTimeField(auto_now=True) open_class = models.BooleanField(default=True) members = models.ManyToManyFiel...

Sharepoint Content Query Web Part: Show items from "events" list that are set to occur or reoccur within a month

I've been reading this msdn post: http://msdn.microsoft.com/en-us/library/aa981241.aspx trying to edit the content query web part to only show items from the event list which either occur within 30 days or reoccur within 30 days. It is straight forward to deal with events which do not reoccur because I can compare [Start Date] to [Today...

Updating a specific key/value inside of an array field with MongoDB

As a preface, I've been working with MongoDB for about a week now, so this may turn out to be a pretty simple answer. I have data already stored in my collection, we will call this collection content, as it contains articles, news, etc. Each of these articles contains another array called author which has all of the author's information...

CodeIgniter static class question

If I would like to have several static methods in my models so I can say User::get_registered_users() and have it do something like public static function get_registered_users() { $sql = "SELECT * FROM `users` WHERE `is_registered` = 0"; $this->db->query($sql); // etc... } Is it possible to access the $this->db object or c...

get n records at a time from a temporary table

I have a temporary table with about 1 million entries. The temporary table stores the result of a larger query. I want to process these records 1000 at a time, for example. What's the best way to set up queries such that I get the first 1000 rows, then the next 1000, etc.? They are not inherently ordered, but the temporary table just has...

Query to check the consistency of records

I have four tables TableA: id1 id2 id3 value TableB: id1 desc TableC: id2 desc TableD: id3 desc What I need to do is to check if all combinations of id1 id2 id3 from table B C and D exist in the TableA. In other words, table A should contain all possible combinations of id1 id2 and id3 which are stored in the other three...

Easy comparing MySQL plans in Django

Hi, is there a way to print out MySQL query for example from this line of code Model.objects.all().order_by(sort_headers.get_order_by()) I want to plan best way of using Django but with > 1 million of objects in my model this is getting too slow. Thanks ...

Django query filter a set of data

if a have a query like following = Relations.objects.filter(initiated_by = request.user) in which i'm having all the users followed by the currently logged in user, and i want to display those user's blog posts. Using a query like: blog = New.objects.filter(created_by = following) it only shows me the blog posts of the use...

how do i do an insert with DATETIME now inside of SQL server mgmt studio

i have a website that does inserts into this table below. I need to do some manual inserts but i wasn't sure how do pass in the equivalent of DateTime.Now in C#. I am running this below from the query editor in sql server mgmt studio. Is there anyway to pass in the current date time in this query below. INSERT INTO [Business] ...

SimpleDB query on attribute name

Hello, I don't know something like this is possible or not with simpledb. I am trying to use following type of simpledb data structure. Each item has multiple name/value pairs (name here is attribute-name) e.g. item1 serial_num -> value item2 serial_num -> value such number of items are there in a domain and there are mu...

How to control ExecuteNonQuery

I mean hypothetically is it possible to control query execution? For example I got a big query and it does a lot of things but suddenly it gets an error, but I don't want to stop its execution, I just wanna skip that step and continue further. Or I want to let the user know what's going on, what's actually is happening on the server ri...

choosing between requery or firing the query again in SQLite

hi Friends, i have been using a SQLite database, Theres a situation where i have a list which displays all the "name" field data of a table "table1". Now i have a button to insert data in "table1". The list is populated using a simple cursor adapter which is passed a cursor "cursor1" populated with the data. "cursor1" is prepared using ...