query

How to update a column adding 1 to the current value

Hi guys, i can't do a relative simple update query in access or sql server. My simple task is: adding 1 to the current value of a column. I'm using this syntax: UPDATE MyTable SET ColumnA = ColumnA + 1 WHERE MyPrimaryKey= 100 But it does't work. Someone can help me ? Thanks bye! ...

Possible to substitute ORDER BY w/ other value if 1st value is empty

Is it possible to replace value field_id_36 with field_id_39 if field_id_36 is empty? SELECT wt.title, wt.url_title, wt.weblog_id, wt.entry_id, wd.field_id_36 FROM exp_weblog_titles wt LEFT JOIN exp_weblog_data wd ON wt.entry_id = wd.entry_id WHERE wt.weblog_id = {weblog_id_insert} ORDER BY field_id_36+0 So in theo...

Union as sub query MySQL

I'm wanting to optimize a query using a union as a sub query. Im not really sure how to construct the query though. I'm using MYSQL 5 Here is the original query: SELECT Parts.id FROM Parts_Category, Parts LEFT JOIN Image ON Parts.image_id = Image.id WHERE ( ( Parts_Category.category_id = '508' OR Parts_Categ...

Difference between two queries when selecting a random sample from oracle

This question answers the question on how to select a random sample from oracle which is exactly what I need. I do not understand however the difference between that solution SELECT * FROM ( SELECT * FROM mytable ORDER BY dbms_random.value ) WHERE rownum <= 1000 and something li...

SQL Elaborate Joins Query

I'm trying to solve the below problem. I feel like it is possible, but I can't seem to get it. Here's the scenario: Table 1 (Assets) 1 Asset-A 2 Asset-B 3 Asset-C 4 Asset-D Table 2 (Attributes) 1 Asset-A Red 2 Asset-A Hard 3 Asset-B Red 4 Asset-B Hard 5 Asset-B Heavy 6 Asset-C Blue 7 Asset-C Hard If I am looking for something havin...

asp.net MVC: Pass query string as a string, or individual parameters?

In asp.net MVC I have a search action in my controller and I am trying to decide If I should pass the query to my repository as a string public ActionResult Search(string query) { return View(_repository.ListPeople(query)); } or as individual parameters: public ActionResult Search(string FirstName, string LastName, System.Nullabl...

Django - finding the extreme member of each group

I've been playing around with the new aggregation functionality in the Django ORM, and there's a class of problem I think should be possible, but I can't seem to get it to work. The type of query I'm trying to generate is described here. So, let's say I have the following models - class ContactGroup(models.Model): .... whatever .....

SQL Insert rows from two corresponding comma delimited sets of strings

I would like to take two separate strings of value pairs delimited by commas and insert each pair into a row in the database. For example: X = "1,2,3" Y = "A,B,C" => X | Y --------- 1 | A 2 | ...

DB2 cascade delete command?

Is there a special syntax to execute a cascade delete on DB2 or is it only possible to create "cascadable" tables by defining them with the "ON DELETE CASCADE" option? What I am trying to achieve is delete other table rows based on a same foreign key when I delete that key, but this is done on an already existing and data-filled databas...

select latest 2 records of each product id in single table

this is my table structure, create table ArticleTbl ( ArticleID bigint identity(1,1), ProductID int , ArticleName varchar(100), PubDate datetime, AuthorName varchar(50), AuthorImage bit, HtmlValues nvarchar(max) ) here productid are 1=creditcard,2=prepaidcard,3 saving account,......... each productid is having multiple rows of reco...

vba sql problem

Below query is showing error Please help : DoCmd.RunSQL ("insert into tbltesting (IsDiff)values ('Yes') where empid= '" & Me.txtEmpId.Value & "' and testid= '" & Me.txtAutoNumber.Value & "'") ...

How to print the Text data type in mysql

A Table has Field: data Type: text select data from t1 where id = 5 *************************** 1. row *************************** data: 1 row in set (0.00 sec) How to print the exact data from table ? NOTE: the Field data is not empty ...

Oracle Query Optimization

I have the following tables Master Table id ---- 1x 2x .... Assignment Table id | type_id | assign_id ----------------------------- 1x | 2 | 554 1x | 3 | 664 2x | 2 | 919 2x | 4 | 514 Type table type_id | create_date ---------------------- 1 | 01/01/2009 2 | 01/...

VBA update query

Below query is resulting zero rows updated but i am sure that there is a record to update DoCmd.RunSQL (" Update tbltesting set IsDiff ='Yes' " & _ "where empid= " & Me.txtEmpId.Value & _ " and testid= " & Me.txtAutoNumber.Value & ";") Please help!! ...

How do I sort a query object in ColdFusion 7?

I have a query object, with, say, fifteen rows returned. For all intents and purposes, I can't modify the SQL which generates the query object, but I need to sort this query object by column. Is there a way to do this in ColdFusion 7 without resorting to an external library? Edit: I should add: I've run a query on this query object, and...

SQL Count(*) and Group By - Find Difference Between Rows

Below is a SQL query I wrote to find the total number of rows by each Product ID (proc_id): SELECT proc_id, count(*) FROM proc WHERE grouping_primary = 'SLB' AND eff_date = '01-JUL-09' GROUP BY proc_id ORDER BY proc_id; Below is the result of the SQL query above: proc_id count(*) 01 626 02 624 03 626 04 624 05 622 06 624 07 ...

How can I update multiple columns with a Replace in SQL server?

How do I update different columns and rows across a table? I want to do something similiar to replace a string in SQL server I want to do this but the value exists in multiple columns of the same type. The values are foreign keys varchars to an employee table. Each column represents a task, so the same employee may be assigned to severa...

MySQL coalesce for some null, not all null

I have a MySQL query that checks an employee schedule DB and (thanks to a previous stackoverflow question) returns any days that the user is not working as "No Work", so that if the user isn't working on Thursday, the query fills in that date even though the date does not appear in the original result set (and so I don't have to fill in ...

VBA select not returning any rows

Below query is not returning any rows into the listbox.There is no error message: lstDiff.RowSource = "select TestScenario,TestId from tblTesting where empid= '" & Me.txtEmpId.Value & "' and testid= '" & Me.txtAutoNumber.Value & "'" Could anyone help? ...

SQL Server table creation date query

How can i get the table creation date of a MS SQL table using a SQL query ? I could not see any table physically but i can query that particular table ...