query

django select query--how do I make this?

class Content(models.Model): .....stuff here class Score(models.Model): content = models.OneToOneField(Content, primary_key=True) real_score = models.IntegerField(default=0) This is my database schema. As you can see, each Content has a score. How do I do this: Select all from Content where Content's Score is 1? ...

Is this an effective and efficient SQL Query or is there a better way?

We have a passwords table which references a user table. Records never get deleted from the password table so if a user changes their password, a new entry with a more recent Created date gets inserted. The hash of the password is salted with various things, most importantly the created date of the actual record. In a stored procedure...

Windows Workflow Foundation 4.0 and Tracking

I'm working with the Beta 2 version of Visual Studio 2010 to get some advanced learning using WF4. I've been working with the SqlTracking Sample in the WF_WCF_Samples SDK, and have gotten a pretty good understanding of how to emit and store tracking data in a SQL Database, but haven't seen anything on how to query the data when needed. ...

In Oracle, why can´t I select rownum in a outer query, when my inner query contains SDO_ANYINTERACT?

I have written a query in Oracle that looks like this: select ID, NAME, GEOMETRY from ( select a.*, rownum as rnm from ( select ID, NAME, GEOMETRY from MY_TABLE where SDO_ANYINTERACT(GEOMETRY, SDO_UTIL.SDO_GEOMETRY('POLYGON ((670000 6268000, 670000 6269000, 700000 6269000, 700000 6268000, 670000 6268000))')) = '...

SQL Server Trigger that works - fires just once

Hello all, I want to do some calculations when my table data is changed. However, I am updating my table manually and copy pasting about 3000 rows in once. That makes my trigger work 3000 times, but I want it to do the trigger only once. Is there a way to do that ? Thanks. ...

OUTER JOIN using IN list?

I'd like to find the hits and misses in a table using only a list of items without having to create a new table to contain the list items and without using any scripting. I do many ad-hoc queries throughout the day so this would be useful. Here's an example of what I'm using now: SELECT custid, name, email FROM customers WHERE cust...

what is the best way to return a auto created guid id?

I have a table that has a newid() for the primary key field (Id) in the stored procedure i need to return this newly created guid back as a return parameter, i could create the guid beforehand and insert into the database, but that would defeat the purpose of a newid(). Is there a good way to handle this? INSERT INTO [SUBS].[dbo].[Sub...

SQL Server , How to compare speeds of simple Queries.

Hello all, I have a big query and I am tring to improve it part by part, however due to the caching mechanism, and simplicity of t-sql codes, I don't have a reliable environment for testing the speeds. The queries that I am tring to improve about speeds are all last about 1 or 2 seconds, so I can't see the difference clearly. And creati...

Get Roles which are still not assigned to member query

How would I query MySQL database to return roles that are still not assigned (like available to him). With table user_roles: |user_id|role_id| | 1 | 1 | | 1 | 2 | | 1 | 4 | | 1 | 7 | How can I query roles table to return role name and id of all the roles that are not assigned. role_id: 3,5,8,... ...

What's the best way to choose a table name dynamically at runtime?

I am using MySQL Connector/Net and I want to write a query against a table whose name will be specified at runtime. This example is off the top of my head (not tested): public class DataAccess { public enum LookupTable { Table1, Table2, Table3 } public int GetLookupTableRowCount(LookupTable tabl...

code igniter update a row using active records

hi All programmer I wanted to update a row using active records in codeigniter, and I only want to increment a field value (received_qty = received_qty +1) , I realized that I can do that in usual sql, but I cant in codeigniter active records $update['received_qty'] = 'received_qty + 1'; $update['received_date'] = date("Y-m-d"); $this-...

Access get all tables

Dear All, Is there a way in by sql statement or vba code to return all tables from access file? "I don't know the name of the tables" like when you want to have all fields in a table you use '*' regardless the names of the fields. but how to get all tables?!!!! ...

sql statement to return all fields from all tables

select * from * yes this is what I want I want to return all fields from all table in my ACCESS database regardless the fields names or the tables names!!! for example if I have table1 and table2 as tables in my database access file what I want is to generate this statement select * from table1,table2 from sql query which run fin...

duplicate value in a postgresql table

Hello i'm trying to modify a table inside my postgresql database, but it says there is duplicate! what is the best way to find a duplicate value inside a table? kinda a select query? ...

Why can I not express this subquery? Is there an alternative?

I get an error: Subqueries are not allowed in this context. Only scalar expressions are allowed. Why are subqueries not allowed? I'm just trying to move some value over to another row in the same database. Is there another way of expression this quickly? (it's just a one-time operation...) INSERT INTO Html_Content (pageid, ht...

Running sql scripts against an attached database?

I've got an MDF attached to an instance of Sql Server 2008 Express, and I need to run some sql scripts against it to generate tables, indexes, etc. But I can't figure out how to get this to work. If I load the scripts in Visual Studio, it only allows me to connect to the server and run it against a database. I can't choose a different...

SQL Query Question: Select all rows of n length, and then append a character

I have a ZIP code column where some of the zips came in without the leading zero. My goal is to: 1) select all rows in the zip column that are four characters in length (e.g. the zip code entries missing a zero) and then 2) append a '0' to these columns. I am able to select the rows: SELECT zip FROM contact WHERE zip LIKE "____...

MySql find all rows where data contains less than four characters

How would I properly write this sql-english query: "SELECT zip FROM tblContacts WHERE [the number of characters in zips is less or equal than 4]". Thanks. ...

What if I want to implement a complicated query in REST

I would like to implement a REST service which is able to parse query such as retrieving the users created after startdate and before endate and with the privilege of admin. It seems that standard REST implementation could only query by ID. Do I need to self-defined protocol to make this kind of query possible or any standard? Thanks! ...

[MySQL/PHP] Encoded query, no space

hi everyone. i would like to know if it is possible to create request with no space with MySQL ? i test the security of my own website, and i've put an str_replace(" ", "", $POST['id']); All sql injection becomes : id=-1 UNION SELECT pass... afet strreplace : -1UNIONSELECTpass i would have a hight livel securoty on my own website. t...