query

Query on Sql Joins

I have three tables. tblLink: (LinkId, LinkName, GroupId, ,SubGroupId) GroupId and SubGroupId are foreign key in tblGroup and tblSubGroup tblGroup: (GroupId, GroupName) tblSubGroup: (SubGroupId, SubGroupName) in tblLink SubGroupId is allowed Null but GroupId is Mandatory. I want to fetch LinkName, GroupName, SubGro...

Pass a php variable to mysql query

Hai guys, What is wrong in this code i get an empty array. i am passing a php variable to the query it didnt work, when i give a hardcoded value the query returns result. echo $sub1 = $examSubject[$i]; $subType = $examType[$i]; $query = $this->db->query("select dSubject_id from tbl_subject_details where dSubjectCode='$sub1'"); print_r(...

How can I execute this WMI Query in VC++ ?

Hi, I recently saw this Stackoverflow question about detecting the "real" version of Windows. I have a application that uses code thats only availible on Windows Vista and up. To maintain compatibility with Windows XP, I have created my own version which does exactly the same as the Vista code, but is nowhere near as fast as the Vista ...

When to begin T-SQL query with USE?

I'm a T-SQl and database newbie, and a little confused. In the T-SQL book I'm reading it says that a USE statement is written to set the database context of the session. Does that mean that there can be more than one database in an instance of SQL-server and the USE statement tells SQL server which database the query will be on? ...

iPhone CoreData Queries

Hey there, I'm new at using CoreData and I'm trying to understand how to perform a query on a table. I can use a fetch request to pull all of the records from a table, but I'm looking for a subset. Is there an easy way to do this? Thanks, Howie ...

ORACLE 11g case insensitive by defalt

Hi all, I found in this article, that since ORACLE 10g, there is a way to make a particular connection-session compare strings case-insensitive, without needing any crazy SQL functions, using an ALTER SESSION. Does anyone know if, in 11g, there might be a way to make the database to always operate in this mode by default for all new co...

Query multiple models with one value

I have multiple models which all have a FK to the same model. All I know is the FK how can I determine which of the models has the FK attached? Below an example to clearify: class ModelA(models.Model): title = models.CharField("title", max_length=80) class ModelB(models.Model): fk = models.ForeignKey(ModelA) class ModelC(...

Indexes for inner joins with where clause

If I had the following query: select some cols from tbl_a INNER JOIN tbl_b ON tbl_a.orderNumber = tbl_b.orderNumber where tlb_b.status = 'XX' Assuming both tables have clustered indexes on order number only, would it be better from a performance perspective to extend the clustered index on table b to include the status column r...

Best way to write this query.

I have two MySql tables as shown below with the data shown: CREATE TABLE `A` ( `id` int(12) NOT NULL AUTO_INCREMENT, `status` varchar(50) DEFAULT NULL, `another_field` varchar(50) DEFAULT NULL ) INSERT INTO `A` VALUES ('1', null, 'a'); INSERT INTO `A` VALUES ('2', null, 'b'); INSERT INTO `A` VALUES ('3', null, 'c'); CREATE TABLE `B`...

sql server: Estimated number of rows is way off

I get a bizarre execution plan behavior from SQL Server (2005). Table: TableName: LOG ID int, Name varchar(50) (Table contains around 1000 rows) Query: Select * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY ID DESC) as Row, ID, Name FROM Log ) as LogWithRowNumbers WHERE Row>=1 and Row<=2 It estimates the number of rows returned a...

How to increase the performance of a Database?

I have designed databases several times in my company. To increase the performance of the database, I look for Normalisation and Indexing only. If you were asked to increase the performance of a database which has approx 250 tables and some tables with millions of records, what different things you would look for? Thanks in advance. ...

What strategies are used to implement type-ahead auto-completion on a large dataset?

I am a .NET WinForms/ASP.NET developer with what I think of as technology agnostic questions about how to implement "type-ahead auto-completion" on a large data set. If someone could point me to a reference implementation or detailed discussion, that would be great, but here are my questions: Presumably, the user starts typing and, aft...

Best way to rewrite a WHERE NOT IN clause?

I've got a query like the one below: Select ser.key From dbo.Enrlmt ser Where ser.wd >= @FromDate AND ser.wd <= @ThrouDate AND ser.EnrlmtStatCode = '4321' AND ser.StuExitCatgCode in ('1','2','3','4','5','6','7') AND ser.Key not in (select Key from Enrlmt ser2 ...

Join two tables based on relationship defined in third table

Hello, I have two tables Activity and Action. One or more actions can be performed for an activity. And the relationships between Activity and Action is given in a third table called Activity Action. How do I retrieve a result set that tells me what action is applicable for each activity using an sql statement? Here's the table structu...

DELETE data from two tables, based on a third's ID

I'm hesitant to run this query which deletes data (for obvious reasons). I would like to delete the the matching rows from two tables, where the ID = the ID of a third table (which i want to remain unaffected) This is the exact query I would like to run: DELETE FROM ItemTracker_dbo.Transaction t, ItemTracker_dbo.Purchase ...

Giving conditions in SQL SELECT statement

Hi All, I have to run an SQL query based on conditions. There are 2 AND conditions that needs to be executed only if the if conditions for them are satisfied. Can we use CASE statement here. If so how? Or are there any other methods?? SELECT * FROM MyTable WHERE col1=@val1 if condition1 here AND col2 = @val2 end if if condition2 her...

django sort query result by occurrence count

I've got the flowing two models: class Item(models.Model): Name = models.CharField(max_length = 32) class Profile(models.Model): user = models.ForeignKey(User, unique = True) ItemList = models.ManyToManyField(Item, related_name = "user_itemlist") For Item X I want to get a list of Item objects present in ItemList for all...

SQLite query runs 10 times slower than MSAccess query

I have a 800MB MS Access database that I migrated to SQLite. The structure of the database is as follows (the SQLite database, after migration, is around 330MB): The table Occurrence has 1,600,000 records. The table looks like: CREATE TABLE Occurrence ( SimulationID INTEGER, SimRunID INTEGER, OccurrenceID INTEGER, Occurren...

building a query string with jquery and checkboxes

Hi I'm building a search form with several filter options on the results page. It's a basic search form, results show in an friendly url such as: domain.com/resuts/country/age/type/ The filters are simply checkboxes which on click, should reload the page with a query string to identify what has been checked/unchecked. (there is no sub...

Apache, LocationMatch: match query string

How can I match a query string using LocationMatch with apache? <LocationMatch "/index.php?a=b.*"> // ... ... won't work unfortunately. Kind regards ...