All Questions

Tagged with
Filter by
Sorted by
Tagged with
1484votes
16answers
1.8mviews

How can I do an UPDATE statement with JOIN in SQL Server?

I need to update this table in SQL Server with data from its 'parent' table, see below: Table: sale id (int) udid (int) assid (int) Table: ud id (int) assid (int) sale.assid contains the ...
user avatar
  • 18.8k
1093votes
27answers
2.2mviews

SQL update from one Table to another based on a ID match

I have a database with account numbers and card numbers. I match these to a file to update any card numbers to the account number, so that I am only working with account numbers. I created a view ...
user avatar
743votes
13answers
1.0mviews

SQL update query using joins

I have to update a field with a value which is returned by a join of 3 tables. Example: select im.itemid ,im.sku as iSku ,gm.SKU as GSKU ,mm.ManufacturerId as ManuId ,mm....
user avatar
  • 205k
489votes
5answers
1.0mviews

How do I (or can I) SELECT DISTINCT on multiple columns?

I need to retrieve all rows from a table where 2 columns combined are all different. So I want all the sales that do not have any other sales that happened on the same day for the same price. The ...
user avatar
  • 30.7k
462votes
9answers
504kviews

how can I Update top 100 records in sql server

I want to update the top 100 records in SQL Server. I have a table T1 with fields F1 and F2. T1 has 200 records. I want to update the F1 field in the top 100 records. How can I update based on TOP ...
user avatar
  • 5,869
431votes
18answers
453kviews

Multiple Updates in MySQL

I know that you can insert multiple rows at once, is there a way to update multiple rows at once (as in, in one query) in MySQL? Edit: For example I have the following Name id Col1 Col2 Row1 1 ...
user avatar
  • 103k
426votes
6answers
474kviews

updating table rows in postgres using subquery

Using postgres 8.4, My goal is to update existing table: CREATE TABLE public.dummy ( address_id SERIAL, addr1 character(40), addr2 character(40), city character(25), state character(2), ...
user avatar
  • 5,275
411votes
12answers
930kviews

How to insert a value that contains an apostrophe (single quote)?

What is the correct SQL syntax to insert a value with an apostrophe in it? Insert into Person (First, Last) Values 'Joe', 'O'Brien' I keep getting an error as I think the apostrophe after the ...
user avatar
  • 175k
292votes
7answers
1.2mviews

Oracle SQL: Update a table with data from another table

Table 1: id name desc ----------------------- 1 a abc 2 b def 3 c adf Table 2: id name desc ----------------------- 1 x 123 2 y 345 In ...
user avatar
  • 22.2k
282votes
8answers
451kviews

mysql update column with value from another table

I have two tables, both looking like id name value =================== 1 Joe 22 2 Derk 30 I need to copy the value of value from tableA to tableB based on check name in each table. Any ...
user avatar
  • 4,191
257votes
2answers
236kviews

How to write UPDATE SQL with Table alias in SQL Server 2008?

I have a very basic UPDATE SQL - UPDATE HOLD_TABLE Q SET Q.TITLE = 'TEST' WHERE Q.ID = 101; This query runs fine in Oracle, Derby, MySQL - but it fails in SQL server 2008 with following error: "...
user avatar
  • 4,599
239votes
3answers
716kviews

I want to use CASE statement to update some records in sql server 2005

UPDATE dbo.TestStudents SET LASTNAME = ( CASE WHEN (LASTNAME = 'AAA') THEN 'BBB' WHEN (LASTNAME = 'CCC') THEN 'DDD' WHEN (LASTNAME = 'EEE') THEN 'FFF' ELSE (LASTNAME) END ) The statement ...
user avatar
  • 2,493
197votes
13answers
708kviews

Update multiple columns in SQL

Is there a way to update multiple columns in SQL server the same way an insert statement is used? Something like: Update table1 set (a,b,c,d,e,f,g,h,i,j,k)= (t2.a,t2.b,t2.c,t2.d,t2.e,t2.f,t2.g,t2.h,...
user avatar
  • 2,425
196votes
8answers
396kviews

MySQL - UPDATE multiple rows with different values in one query

I am trying to understand how to UPDATE multiple rows with different values and I just don't get it. The solution is everywhere but to me it looks difficult to understand. For instance, three updates ...
user avatar
164votes
10answers
310kviews

Increment value in MySQL update query

I have made this code for giving out +1 point, but it doesn't work properly. mysql_query(" UPDATE member_profile SET points= ' ".$points." ' + 1 WHERE user_id = '".$...
user avatar
  • 16.9k

15 30 50 per page
1
2 3 4 5
377