query

Oracle get previous day records

Ok I think I'm getting the previous year instead of the previous day, but I need to previous day. SELECT TO_DATE(TO_CHAR(CURRENT_DATE, 'YYYY-MM-DD'),'YYYY-MM-DD') - 1 FROM Dual I'm comparing it to a datetime stamp in this format and wish to get all the rows from the previous day. YYYY-MM-DD HH:MM:SS So I'm trying something like thi...

Selecting data from SQL Server table according to Month

I have to come up with a way to get data from a SQL server table given it's month There's a smalldatetime type field called "date" in the "events" table and a field from it looks like this: 29/01/2003 17:00:00 It should be one among those that appear in the gridview when I select jan/03 in a given DropDownList control in ASP.NET. Wh...

SQL-query task, decision?

There is a table of currencies rates in MS SQL Server 2005: ID | CURR | RATE | DATE 1   | USD   | 30      | 01.10.2010 3   | GBP   | 45      | 07.10.2010 5   | USD   | 31      | 08.10.2010 7   | GBP   | 46      | 09.10.2010 9   | USD   | 32      | 12.10.2010 11 | GBP   | 48      | 03.10.2010 Rate are updated in real time and there are ...

Is it possible to write a query which returns a date for every day between two specified days?

Basically, the question says it all. I need a PL\SQL query that returns a list of dates between two dates such that for 01-JAN-2010 to 20-JAN-2010 I would get 20 rows returned: the_date -------- 01-JAN-2010 02-JAN-2010 03-JAN-2010 04-JAN-2010 ... 20-JAN-2010 ...

select with conditions on array of composite types (postgresql)

For example I have type: CREATE TYPE record AS ( name text, description text, tags text[]) And table: CREATE TABLE items ( id serial, records record[] ) How can I select all items with records with tags 'test' (without using PL/pgSQL)? ...

LINQ-to-SQL load keyword from variable

public IQueryable<ArticleDisplay> SearchNumberOfArticles(int articleNr, string order) var result = ( from category in db.ArticleCategories join article in db.Articles on category.CategoryID equals article.CategoryID orderby article.Date order ...

PHP inserting Apostrophes where it shouldn't

Hi folks Not too sure what's going on here as this doesn't seem like standard practise to me. But basically I have a basic database thingy going on that lets users submit code snippets. They can provide up to 5 tags for their submission. Now I'm still learning so please forgive me if this is obvious! Here's the PHP script that makes i...

How can I remove an "ALMOST" Duplicate using LINQ? ( OR SQL? )

This should be and easy one for the LINQ gurus out there. I'm doing a complex Query using UNIONS and CONTAINSTABLE in my database to return ranked results to my application. I'm getting duplicates in my returned data. This is expected. I'm using CONTAINSTABLE and CONTAINS to get all the results I need. CONTAINSTABLE is ranked by SQL a...

LINQ to SQL join when there aren't results

Given the following database structure I'm trying to write a LINQ query that will return images grouped by tags it's associated with. So far I've got this: var images = from img in db.Images join imgTags in db.ImageTags on img.idImage equals imgTags.idImage join t in db.Tags on imgTags.idTag equals t.idTag where img.OCRDa...

What database field should this be?

I have a table called "Event". A column has "duration"--which is...how long that event lasts. What database type should this be? Integer? (in seconds)? In the future, I will do statements such as: If now() > event.duration THEN don't display the event. ...

Trouble with a query

Hi there, I'm having trouble with a query in SQL Server 2008 on some forex trading data. I have a trades table and an orders table. A trade needs to comprise of 2 or more orders. DDL schema and sample data below. What I want to do is write a query that shows the profit/loss in pips for each trade. A pip is 1/1000th of a currency. So th...

Querying Same Lookup Table With Multiple Columns

I'm a bit confused on this. I have a data table structured like this: Table: Data DataID Val 1 Value 1 2 Value 2 3 Value 3 4 Value 4 Then I have another table structured like this: Table: Table1 Col1 Col2 1 2 3 4 4 3 2 1 Both columns from Table1 point to the data in ...

How can I remove this query from within a loop?

I am currently designing a forum as a personal project. One of the recurring issues I've come across is database queries in loops. I've managed to avoid doing that so far by using table joins or caching of data in arrays for later use. Right now though I've come across a situation where I'm not sure how I can write the code in such a w...

Get most left|right|top|bottom point contained in box

I'm storing Points Of Interest (POI) in PostgreSQL database, and retrieve them via PHP script to Android application. To reduce internet usage I want my mobile app to know if there are any points in the neighborhood of currently displayed area. My idea is to store bounds of the rectangle containing all points already retrieved (in other...

Php/Mysql - need help to insert and update multiple rows with a single query

Hello, is there any way how in this situation insert and update DB with single queries? $message = 'Hello to all group members'; $userdata = mysql_query("SELECT memberid, membernick FROM members WHERE groupid='$cid'") or die('Error'); while(list($memberid, $membernick) = mysql_fetch_row($userdata)) { $result1 = mysql_query("I...

Django ORM: Ordering w/ aggregate functions — None special treatment

Hi, I'm doing query like that: SomeObject.objects.annotate(something=Avg('something')).order_by(something).all() Now, I normally have an aggregate field in my model that I use with Django signals to keep in sync, however in this case perfomance isn't an issue so I thought I'd keep it simple and just use subqueries. This approach, h...

How can I write a MySQL query to check multiple rows?

I have a MySQL table containing data on product features: feature_id feature_product_id feature_finder_id feature_text feature_status_yn 1 1 1 Webcam y 2 1 1 Speakers y 3 1 1 ...

What is the port for a hostname query ?

I want to query an IP to get its hostname. What is the standard port for this ? Could it be port 101 listed under "hostnames" in /etc/services ? ...

How to insert Search Query into MYSQL - Check for Double Words

Hi, what is the best method to insert a search query into MySql and check for double words? (for showing up the last searches and a collection of searches) maybe something like this: < ?php /*------------------------------ Read and save the search query -------------------------------*/ $querystat = mysql_real_escape_string($_GET['q'...

Join Query returns empty result, unexpected result

Hello all, Can anyone explain why this query returns an empty result. SELECT * FROM (`bookmarks`) JOIN `tags` ON `tags`.`bookmark_id` = `bookmarks`.`id` WHERE `tag` = 'clean' AND `tag` = 'simple' In my bookmarks table, I have a bookmark with an id of 70 and in my tags table i have two tags 'clean' and 'simple' both that have the colu...