UPDATE multiple rows with different values in one query in MySQL

You can do it this way: UPDATE table_users SET cod_user = (case when user_role=”student” then ‘622057’ when user_role=”assistant” then ‘2913659’ when user_role=”admin” then ‘6160230’ end), date=”12082014″ WHERE user_role in (‘student’, ‘assistant’, ‘admin’) AND cod_office=”17389551″; I don’t understand your date format. Dates should be stored in the database using native date and time types.

SQL Server loop – how do I loop through a set of records

By using T-SQL and cursors like this : DECLARE @MyCursor CURSOR; DECLARE @MyField YourFieldDataType; BEGIN SET @MyCursor = CURSOR FOR select top 1000 YourField from dbo.table where StatusID = 7 OPEN @MyCursor FETCH NEXT FROM @MyCursor INTO @MyField WHILE @@FETCH_STATUS = 0 BEGIN /* YOUR ALGORITHM GOES HERE */ FETCH NEXT FROM @MyCursor INTO @MyField … Read more

Concatenate multiple result rows of one column into one, group by another column [duplicate]

Simpler with the aggregate function string_agg() (Postgres 9.0 or later): SELECT movie, string_agg(actor, ‘, ‘) AS actor_list FROM tbl GROUP BY 1; The 1 in GROUP BY 1 is a positional reference and a shortcut for GROUP BY movie in this case. string_agg() expects data type text as input. Other types need to be cast … Read more

How to insert multiple rows from a single query using eloquent/fluent

It is really easy to do a bulk insert in Laravel using Eloquent or the query builder. You can use the following approach. $data = [ [‘user_id’=>’Coder 1’, ‘subject_id’=> 4096], [‘user_id’=>’Coder 2’, ‘subject_id’=> 2048], //… ]; Model::insert($data); // Eloquent approach DB::table(‘table’)->insert($data); // Query Builder approach In your case you already have the data within the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)