UPDATE multiple rows with different values in one query in MySQL

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 into 1 query: UPDATE table_users SET cod_user=”622057″ , date=”12082014″ WHERE user_rol=”student” AND cod_office=”17389551″; UPDATE table_users SET cod_user=”2913659″ , date=”12082014″ WHERE … Read more

How to perform update operations on columns of type JSONB in Postgres 9.4

Looking through the documentation for the Postgres 9.4 datatype JSONB, it is not immediately obvious to me how to do updates on JSONB columns. Documentation for JSONB types and functions: http://www.postgresql.org/docs/9.4/static/functions-json.html http://www.postgresql.org/docs/9.4/static/datatype-json.html As an examples, I have this basic table structure: CREATE TABLE test(id serial, data jsonb); Inserting is easy, as in: INSERT INTO test(data) … Read more

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 work for the purpose but the else condition scan through every record in the table. Is there any way I can leave the unaffected … Read more

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: “Msg 102, Level 15, State 1, Line 1 Incorrect syntax near ‘Q’.” If I remove all occurrences … Read more

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), zip character(5), customer boolean, supplier boolean, partner boolean ) WITH ( OIDS=FALSE ); Initially i tested my query using insert statement: insert into address customer,supplier,partner SELECT case when cust.addr1 is not … Read more