query

Help Building SQL query

Hi all. I have following 2 tables Channels: Id int PK Title varchar SubChannels: ChannelId int SubchannelId int When I receive data from service I'm trying to persist it to SQL. I receive a few Channel instance, so I store it in Channels table, after that I'm trying to persist every subchannel (every channel contains list of subchann...

mysql: how to write a table of views

I think my question is best explained via an example: Suppose I want to write a webserver for streaming music. I have the following columns in the songs table: |song_id|song_name|song_genre|song_length|artist I would like to enable my users to save playlists, but I don't want my playlists to be defined by explicitly specifying the songs...

which is fastest win32 or SQL query?

Hi, I'm writing a client-server win32 application in Delphi 7 and in a section i need to bring aprox. 100k (less or more) rows with data from an Oracle database. Everything ok so far, but one of the fields must be calculated (a simple division with a large number). My question is, how is less resources consuming and optimum, to make th...

Updating multiple rows with different values

I got this table in my MySQL database, 'users'. It has the fields 'id' and 'value'. Now, I want to update lots of rows in this table with a single SQL query, but many rows should get a different value. Currently, I'm using this: UPDATE users SET value = CASE id WHEN 1 THEN 53 WHEN 2 THEN 65 WHEN 3 THEN 47 ...

How to fetch data from oracle database in hourly basis

Hi all, i have one table in my database say mytable, which contents request coming from other source. There is one column in this table as Time, which stores date and time(e.g. 2010/07/10 01:21:43) when request was received. Now i want to fetch the data from this table on hourly basis for each day. Means i want count of requests database...

Need help for SQL select query for this two table

Table Capture image : http://img844.imageshack.us/img844/6213/99730337.jpg ------------ PositionTable------------ ID ContentFK Position 11 100 1 12 101 1 13 104 2 14 102 2 15 103 2 16 105 3 17 106 3 18 1...

Not being able to order by includes on Rails3

I have the following expression: user.clocks.includes(:users, :runs => :user_runs).find_by_id(params[:id]) which seems to work fine. But when I add an orders, like this: user.clocks.includes(:users, :runs => :user_runs).orders("users.names").find_by_id(params[:id]) it breaks with the following error: ActiveRecord::ConfigurationErr...

Pass along & sign with href to php page help

I have this: browse_cat.php?cat_gr='Mopeds & Traktors'"> The browse_cat.php contains this to fetch the above "category": $cat=$_GET['cat_gr']; echo $cat; This echo outputs the first word only "Mopeds". It wont change if I replace the & with &. What is the problem here? The adress bar when I enter browse_cat.ph...

Why does my SQL query of date fields sometimes need trunc() (Oracle)?

I have two tables where I was querying on a date column in each table. In one case need to use the trunc() function on the date field to get values back, on the other I do not. That is this works on table 1: SELECT to_char( datecol1 ,'mm/dd/yyyy hh:mm:ss') FROM table1 where datecol1 =to_date('10/07/2010', 'mm/dd/yyyy'); But o...

Weighted average calculation in MySQL?

I am currently using the following query to get some numbers: SELECT gid, count(gid), (SELECT cou FROM size WHERE gid = infor.gid) FROM infor WHERE id==4325 GROUP BY gid; The output I am getting at my current stage is the following: +----------+-----------------+---------------------------------------------------------------...

How to get rightmost 10 places of a string in oracle

Hi, i am trying to fetch an id from an oracle table. Its something like "TN0001234567890345". What i want is to sort the values according to the right most 10 positions. I am using oracle 11g. Is there any funcrion to cut the rightmost 10 places in oracle ? thanks in advance tismon ...

how to modify complex sql query w/ join into rails 3

I'm working on a car pooling application where users can add lifts and are able to select multiple stops for each lift ( A to B via c, d, e). Now when a user searches the database for a lift the results should also include lifts like 'A to d', 'c to B' or 'c to e' and so on. I got this working with Rails 2.3.5 using the below code but st...

Filtering of an Object's property's property in google app engine

In an App Engine app, I store registered members in a table that looks like this: class Member(db.Model): user = db.UserProperty(required=True) #other stuff The problem starts when I need to check if a User is already in my Member table. GAE documentation says user value is not guaranteed not to change in time since it is comp...

Is an invalid DB query slower than a valid one? (MySQL)

This is kind of a weird question but... If I run this query in MySQL: SELECT something FROM table WHERE id IN (); which is obviously invalid, do I get some kind of time penalty (exception throwing, logging, something), compared to throwing a valid query? The reason I'm asking is because I just found out an app I'm maintaining (not wri...

Linq query question: Distinct based on object's property

I am aggregating multiple List's into one List and would like to make it distinct based on one of the properties of Foo (Foo.Prop1).. I do not have access to modify Foo's Equality comparer. Dictionary<string, List<Foo>> fooDictionary = new Dictionary<string, List<Foo>>(); List<Foo> foovals = (from e in fooDictionary ...

Drupal 6: How to sort/filter search results by date

Hello, How to customize standard search behavior in Drupal 6? I need search results to be sorted by date. In example, people want to show items within 2 past weeks or something like that. I've tried a lot things on this reference without luck. Have you ever encountered such problem? Any help will b appreciated. Thanks! ...

Simplifying overly complicated LINQ query - queries

public partial class MembershipModule : BaseEntity<MembershipModule> { /// <summary> /// Returns wheter a module is accessible /// </summary> public static bool IsAccessible(MembershipModule module) { // In absence of a module, no security applies to the page if(module == null) return true;...

How to update Drupal Views 2 query with OR expression?

I'd like to add an OR expression to Drupal 6.x Views 2 query in the following way: Existing query: SELECT node.nid AS nid FROM node node WHERE (expr1) AND (expr2) New query - this is what I want to achieve: SELECT node.nid AS nid FROM node node WHERE (expr1) AND (expr2 OR new_expr) The question is how to update my existing query (...

Hibernate query where item in list

Can anyone suggest the correct syntax for a where clause using in applied to a list? The following query in an .hbm file generates a parse exception: <query name="Nutrient.findNutrients1"> <![CDATA[from Nutrient as nutrient where nutrient.id in elements(?)]]> </query> The exception follows: PARSER.reportError(56) | line 2:95: ...

SQL Server 2005 and Datanucleus problem (ntext query)

Started getting errors with SQL Server 2005 This is the first time i've tested our app with Datanucleus 2.x (last test was made with DN 1.x) I use Eclipse RCP. Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The ntext data type cannot be selected as DISTINCT because it is not comparable. at com.microsoft.sqlserver.jdbc.SQL...