query

Django query negation

Hi, I know how to build filters and Q objects in django, but I don't know how to negate the operators that the API provides, for example for the contains operator I would like something like notcontains. e.g. q=Q(name__notcontains="SomeString") This would get me all objects whose name do not contain "SomeString". Is there some synt...

Using T-SQL to get contents of backup media

Hello all, In SQL Server Management Studio (I have 2008), I can see the contents of the media i have backed up to, be it disk or tape. I can see information such as what files it currently includes, the dates they were backed up, etc... Is there a way to do this in T-SQL? I would like to specify a device (which is linked to a fil...

MySQL Find the total amount of posts per user

Hello I have a Database with the following two tables, USERS, POSTS I am looking for a way to get the count of how many posts a user has. Users Posts +----+------+ +----+---------+-----------+ | ID | Name | | ID | user_id | Name | +----+------+ +----+---------+-----------+ | 1 | Bob | | 1 | 1 | B...

Entities cannot be cast to java.lang.Double

public static List<Transaction1> debitSourceAccBalance (Integer youraccinput, Integer toaccinput, String recname, Double amtsender) { EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); Query q = em.createQuery("SELECT t from Transaction1 t where t.fromAccNo =:youraccinput AND t.toAccNo =:toaccinput A...

SQL. How to work/compare/find differences within different rows in the same table.

Hello, I have a table which looks like this: ID Date Size Marked 1 2010-02-02 2 X 2 2002-02-02 1 1 2010-02-03 2 X 2 2010-02-03 3 3 2010-02-03 4 X And I have a code (PHP) which does following things: a) Calculate sum of sizes per day b) Find the difference between tot...

Joining multiple unrelated tables in MySQL

I have a site that stores <select> options in a number of tables, and extracts all of the relevant ones depending on the individual page. At the moment, I wind up with a query like this: SELECT foo FROM foo_tbl;SELECT bar FROM bar_tbl;etc. It's not really a bad problem, but I have to iterate over each select result individually. I'd l...

batch file command

i want to write a query to a file... echo select * from emp where salary >= 0 >>emp.sql but it refuses to accept >= symbol as > used for redirection... any other way? I want to write the query in the program itself.... not by passing already written file... ...

Help finishing MySQL Query?

I have two tables users - id - name - email users_groups - user_id - group_id There are a couple more fields but these are the ones I am trying to grab. I am trying to return 'id, name, email, group_id'. I think I have the first part of the query right, I just don't understand how do the WHERE statement. Could someone show me the way...

Getting messages 1-20, 21-40,... from a database

I'm trying to build a mailbox where we can group the messages in x. If you put x to 20 you'll see messages 1-20 on the first page, opening the second page will show message 21-40 etc. How do I efficiently query this? The best I could come up with is this: select top 20 * from tbl_messages where tnr_id not in ( select top 40 tnr_i...

One to many link table causing duplicate rows returned

Everything I've seen so far is about removing duplicate entries in a database automatically. I want to stress at the beginning of this that there is no duplicate data in the database. I'll also start with the fact that I'm very much still learning about RDBMS design, normalization, relationships, and, most of all, SQL! I have a table ...

Need a way to count entities in GAE datastore that meet a certain condition? (over 1000 entities)

I'm building an app on GAE that needs to report on events occurring. An event has a type and I also need to report by event type. For example, say there is an event A, B and C. They occur periodically at random. User logs in and creates a set of entities to which those events can be attributed. When the user comes back to check the stat...

Advanced many2many query for MYSQL

I im trying to build a imagegallery where people have access to different groups and the groups decide what catalogues and images they are allowed to see. I though many2many structure would be best for this. So far, ive manage to build the database like this: image (image_name, image_file, image_id) catalog (catalog_id, catalog_nam...

mysql_query returns false after successfully executing query in PHP

I have a strange bug where I call an insert query, it executes successfully (the row appears in the DB) but mysql_query returns false. It only returns false when a particular field contains an underscore or dash (or probably some other chars but these are the two I've run into so far). "INSERT INTO Hoopoes (name, owner, dbuser, dbpass,...

sqlite & flex - insert into or ignore problem

I'm using flex to develop my first desktop app and I'm working with sqlite for the first time as well. I'm creating my database and all the tables just fine, but I would also like to add a few rows of data into a couple of the tables so the information is present on first install. The only problem I'm having is every time I run the pro...

How do I strip spaces out of data in a SharePoint column?

I have a MOSS 2007 list with a column which contains hundreds of business and city names. These names are text commonly with multiple words, such as "City of Austin". I have setup filtering and data view web parts to allow a page to display contents of the list based on a query string. All works well, except that I need to generate th...

Trying to insert into multiple tables via web forms page (SQL, ASP.net)

Good Morning Stack Overflow, I'm new to asp.net and have a problem I'm trying to sort out, maybe you can help? The result im looking for is that the data goes into CANRADcontacts and CANRADcollreg which share a common ID. I am populating the database via a web form, and can't quite get the SQL correct, please see this example; Protec...

Need help with MySQL JOINs dealing with four tables

I need help with a MySQL query. This example is much simpler than the one I actually need, but it's similar. Here are my example tables, I tried to make it easy to read. posts --------------- id date 1 2010 2 2010 posts_tags --------------- post_id tag_id 1 1 1 2 1 ...

Need Help with SQL Query in Access

Hi Guys. I have been handed a database to run a few queries on. For one query I have to find the top 10 applications, from two different tables with hundreds of records. then on row (11) I will need to SUM or Count the remaining records and name the row "Other". I have worked out the following code so far. SELECT TOP 10 ApplicationTb...

Selecting records from the past three months

Hi Everyone, I have 2 tables from which i need to run a query to display number of views a user had in the last 3 months from now. So far I have come up with: all the field types are correct. SELECT dbo_LU_USER.USERNAME , Count(*) AS No_of_Sessions FROM dbo_SDB_SESSION INNER JOIN dbo_LU_USER ON dbo_SDB_SESSION.FK_USERID =...

Optimize Select Query

Hi, I am using SQL 2000, and I am running a simple select statement on a table containing about 30 million rows. The select query looks like: select col1, col2, col3 from Table1 where col4=@col4 and col5=@col5 and col6=@col6 The table has a clustered index in it (i.e. a primary key), but that is not being used as a where criteria. All...