query

Efficient query to get all child nodes of a tree (mysql)

I'm looking for an efficient query to return the child nodes of a tree . The data structure is: `ct_cid` int(10) unsigned NOT NULL default '0', // the data `ct_level` int(10) unsigned NOT NULL default '0', // the level (0 = topmost) `ct_parent` int(10) unsigned NOT NULL default '0', // parent ct_cid I need to make sure there won...

Searching free accomodation

I need help with a query? I have 2 tables reservations & units among others. Table reservations has columns ResId,rfrom(datetime),rto(datetime),status(int),UnitID(foreign key). Status 2 means its confirmed. I need to get all free units in requested period, query needs to return only that units for which there aren't confirmed reservatio...

What is wrong with this query (Select as RES1 Union Select where param IN (RES1)

The query: SELECT ct_cid as level1 FROM cat_tree WHERE ct_sid=$sid_int AND ct_parent =$cid_int) UNION (SELECT ct_cid as level2 FROM cat_tree WHERE ct_sid=$sid_int AND ct_parent IN level1) The query is supposed to find the child nodes up to 2 levels of a tree node. I get "You have an error in your SQL syntax; check the manual that corr...

Mysqli Error: Column count doesn't match value count at row 1

Below is the mysqli query that is being performed, anyone know what I get such error: $sql = mysqli_query($db, "INSERT INTO `tbl_bugzilla` (`id`, `by`, `title`, `content`, `date`, `application`,`priority`, `assigned`, `status`) VALUES (NULL, '".$_SESSION['exp_user']['username']."', '" .$_SESSION['exp_user']['username']...

Can't reload ActiveRecord association from controller

Spent a working day on this. I have class Box has_many :users, :through => :subscriptions end I also have custom insert_new_users and associate_with(new_users) methods which use multiple INSERT to do their job quickly. Anyway, they work fine. I also have this line at the end of "associate_with" method: def associate_with # mysql...

XML Query in SQL Server 2008

I am just starting to use XML within SQL Server 2008. I have the data in the XML, but I am having a hard time finding good examples of querying the data. Can someone point me to a good place to start? For example, I would want to find all rows within SQL server that contain a certain criteria within the XML like all rows where the XML...

How can I nest these two SQL queries in MS Access 2007?

I have a table called baskets with these columns: basket (name of the basket) colour (colour of the basket) apples (the number of apples in the basket) bananas (the number of bananas in the basket) oranges (the number of oranges in the basket) pears (the number of pears in the basket) peaches (the number of peaches in the basket) Wit...

Advanced grouping without using a sub query

Hi guys This is a sample of the data that I have. -ID- -Rank- -Type- -Status- -Amount- 1142474 2 Under Offer Approved 23 1148492 1 Present Current 56 1148492 2 Under Offer Approved 3 2273605 1 Present Current 24 Where the ID is the same I only want the record with the highest rank. So the end result of the query....

How to avoid hardcoded field names in HQL, Hibernate?

Suppose that I have the following HQL: String hql = "select e.aField from MyEntity as e"; If I want to refactor and change the name of the MyEntity's member variable aField to something else, I also have to change all occurrences in the whole code in Strings. If I forget to change one hql string the code breaks. How can I avoid this ...

fetching row numbers in a database-independent way - django

Let's say that I have a 'Scores' table with fields 'User','ScoreA', 'ScoreB', 'ScoreC'. In a leaderboard view I fetch and order a queryset by any one of these score fields that the visitor selects. The template paginates the queryset. The table is updated by a job on regular periods (a django command triggered by cron). I want to add a...

Executing Line/Multiple Lines Only in mySQL Query Browser

I already used Microsoft SQL Server 2005 and found really easy to execute single/multiple lines of an sql query. Example: insert into tablea ($vala, $valb, $valc) values ($vala, $valb, $valc); insert into tableb ($vala, $valb, $valc) values ($vala, $valb, $valc); How can I execute the second part only? In MSSQL i will highlight the...

How do i make custom query with wordpress?

Hi, i need to make a query in a wordpress plugin but i couldn't find a wordpress function and i'm not sure is right to use mysql_query the functions i've found enable ordering and grouping but i need to use also join and in (list) is there a way? thank you ...

Problem with a MS Access query after a "Compact and repair" operation.

I have an Access application that use the classical front-end/back-end approach. Yesterday, the backend got corrupted for a reason I don't know. So I opened the backend with Access 2003 and access asked me if I wanted to repair the file, I said yes and it seemed to work. I can open the database see the tables contents and run most of th...

SQL query to find single, sorted record

Here is the problem I am trying to solve. I have a table where I store a StartExclusionDate and EndExclusionDate and set an ApplyDate for my object (called Exclusion). There can be many ExtId entries in the table. I want to get the ApplyDate from the last continuous record where a date passed to the query is included between the Start...

calculate frequency using sql

I have a table in MySQL: Col1 | Col2 a A a B c C a B i want to create a table like this: col1 | col2 | freq a A 0.33 a B 0.67 col1 is a specified item in Col1. col2 is distinct item that has occured with the specified item(i.e. a). freq column is the frequency of appearence...

Lucene: How to do wildcard search inside a Term?

I've the following lucene index: Document A item = level:(1) item = level:(2) item = level:(3) Document B item = level:(1) item = level:(4) Suppose I want to search for all documents which contain level:(1) AND level:(2) ? The Lucene query could be like: "item:level\:\(1\) AND level\:\(2\)" but is it also possible to do something...

Intime and OutTime for the Modified date

Question is already posted on June 4, but still am not get the Proper answer Again Table Structure: T_Person – Table 1 CARDNO 168 471 488 247 519 518 331 240 518 386 441 331 T_Cardevent – Table 2 CARDEVENTDATE CARDEVENTTIME 20090225 163932 20090225 164630 20090225 165027 20090225 165137 20090225 165147 20090225 1657...

How can I to order an EntityQuery query in a seam app?

My project was originally generated by seam-gen and the action "List" bean, OfficeViewList looks pretty much like it did when first generated. The bean extends EntityQuery. Now I want to order the results. What is the best way to do this? Do I want to add some kind of "order by" class to my EJBQL? Or do I want to set the select order...

MySQL: Retrieving count of records from a particular time frame

So what I'm trying to do is a bit tricky. I'm trying to come up with a sql query that will be able to return counts for specified time frames. So I have a table 'v'. Here is some basic data from Table v Table v _____________ id p_id created_at 1 1 2009-06-09 18:54:17 2 2 2009-06-09 21:51:24 3 2 200...

how to search all / wildcard in lucern solr

I'm using RoR + acts_as_solr to query a Solr database. I'm used to using "*" to select all, thanks to MySQL, but that command fires an exception in Solr. Are they other wildcards I can use? Suggestions? Thanks! ...