query

Optimize SQL join query for NHibernate

Take a fairly simple domain model Orders, items and shipments where the Order is a root entity and shipment is a root entity. I want to look up all shipments for a given order. The query is pretty straight forward but I'm seeing undesired behavior with NHibernate. The Model public class Order { public Order(){ Items = new List<LineIte...

How to use results of one sql query within a sub-query

Hey Guys I have to answer the following question "For each year in the database, list the year and the total number of movies that were released in that year, showing these totals in decreasing order. That is, the year(s) with the largest number of movies appear first. If some years have the same number of movies, show these in increasi...

PHP - Displaying page that uses query string, but without any variable

I have a page called Error.php. Variables are usually passed to it using the query string so that it will display the corresponding message to the error code I have assigned. Example: Error.php?id=1 Here is the section of my page below: <?php if($_GET["id"] == "0") { echo "Display certain information..."; } elseif($_GET["id"] == "...

TFS Query to show items changed yesterday by specific user

Does any one knows how to create a query for tfs that will show items changed yesterday by specific user? I need to view what items was done by team yesterday. ...

How do you programmatically turn off eager fetching with hibernate?

I have in my mapping an association to an eagerly loaded collection (lazy="false" fetch="subselect"). How can I turn that off programmatically with Hibernate when I do a query? Thanks ...

Matching a value to multiple columns (in one statement) from a table using MySQL

I'm working with a table in MySQL that contains the following columns: id, january, february, march, april, etc The data in the table looks like this: aa, 0, 0, 1, 0 ab, 1, 0, 1, 0 ac, 1, 1, 0, 0 ad, 1, 1, 1, 0 To query it, I could easily do this: select * from table where january = 1 and february = 1 The result would be: ac, 1...

MySQL Union Query w/ Left Join - Order By Error ?

We have a Union Query. Here's a basic (similar) example: SELECT a.Name, b.Info FROM a LEFT JOIN b ON (a.ID = b.ID) WHERE a.Name LIKE "a%" UNION SELECT a.Name, b.Info FROM a LEFT JOIN b ON (a.ID = b.ID) WHERE a.Name LIKE "b%" ORDER BY a.Name, b.Info; I am receiving an error that says "Unknown column 'b.Info' in 'order clause'". When...

How Do I Query for "Per Day" results for a given date range in MS SQL?

Sorry if this has been asked before. I tried looking through the related questions and didn't find anything that I thought was relevant. Anywho, I would like to build a query that will pull the number of rows that were created on a given date range and time frame. In other words. the date range would be for a given month, but I only wan...

Optimizing MySQL Query, takes almost 20 seconds!

Hi all, I'm running the following query on a Macbook Pro 2.53ghz with 4GB of Ram: SELECT c.id AS id, c.name AS name, c.parent_id AS parent_id, s.domain AS domain_name, s.domain_id AS domain_id, NULL AS stats FROM stats s LEFT JOIN stats_id_category sic ON s.id = sic.stats_id LEFT JOIN cate...

Cross tab query with boolean fields as row headers.

I currently have a table structure that looks something like this(some details omitted): ColumnName || Type Date_Of_Job DateTime Reparied_Service Boolean Disconnect_Service Boolean Relayed_Service Boolean Reparied_Stopcock Boolean Replaced_Stopcock Boolean TPFNR_Repaired ...

MySQL - Finding out Balancing Figure From 2 Tables

I have 2 tables like this: Stock Table product_id bigint(20) qty float Sales Table product_id bigint(20) qty float Sample Data Stock Table product_id---qty 1---10 2---11 3---20 4---50 1---10 3---10 Sales Table product_id---qty 1---2 2---5 3---20 4---40 1---7 I want the following Output after running the Query product_id---qty ...

MYSQL INSERT SELECT problem

Hey all, i have a little difficulty in understanding how to do some INSERT SELECT. For instance i have two tables. TABLE : users id | name | gender 1 | John | m 2 | Mary | f TABLE : website fid | url | id 1 | www.desilva.biz | 2 2 | gidhelp.com | 4 Now let's say i want to add anoth...

Simulation of long-running Oracle DB query

What is the simplest (preferably without any new table creation) way of running a database query which takes long time (at least several minutes) in Oracle DB? ...

How to write a query showing records from table A without a matching record in table B?

Say I have two tables called A (fields: id, phase, name) and B(fields: id, AID, APHASE, void). I need to show all records from A except for records where A.id = B.AID and A.phase = B.APHASE and void = 0. Environment is MySQL. ...

Query most recent TWO entries per widget

I have two tables. One (Widgets) has a list of widgets (ID, widget_name, color, etc...) and data about them. The other one (Tests) has a list of tests run on the widgets (ID, date, info1, info2, etc...). What I want to do is display the most recent TWO tests. I dont think i really need to use the table Widgets for this but i described ...

Preg_replace solution for prepared statements

Hi Guys, I have a command class that abstracts almost all specific database functions (We have the exactly same application running on Mssql 2005 (using ODBC and the native mssql library), MySQL and Oracle. But sometimes we had some problems with our prepare method that, when executed, replaces all placeholders with their respective val...

SQL Query - Copy Values in Same Table

So I have a table that looks like this: ProjectID TaskID Date 000 001 10/28/09 000 002 12/1/09 000 003 02/24/10 001 001 04/14/10 001 002 07/5/10 001 003 02/24/11 002 001 06/07/10 002 002 07/7/10 002 ...

Reverse wikipedia geotagging lookup

Wikipedia is geotagging a lot of its articles. (Look in the top right corner of the page.) Is there any API for querying all geotagged pages within a specified radius of a geographical position? Update Okay, so based on lost-theory's answer I tried this (on dbpedia query explorer): PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos...

Power in sparql and other math functions

Hi I am trying to write a sparql query where I want to filter on the square of something, but I am simply unable to figure out how to square a number (x^2) (except by multiplying it with itself of cause.) I guessed a square root function called math:sqrt() which works, yet nothing like math:pow seems to exist. How do I get the square o...

sql complex group query

I have a table with the following rows: id. type - link 1. image - http://1 2. image - http://2 3. text - none 4. video - http://.. 5. image - http://.. 6. text - http://.. I want to group the type (image) by date, so they show as single row. In this example, the first two images will merge together and output will be like...