473,382 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Update multiple columns with a SELECT statement

5
I have a list of playlists that has different start date and end date. It's a playlists that changes every 3 days or so. I have a code that calculate the number of exposures of that certain playlist. Since, the dates changes constantly and my code for the exposures is based on the dates, I created a table where if the client publish a different playlist, the number of total exposures taken by the previous playlist will be saved in that table which is the playlist_exposures.

What I did was, my code checks if the playlist_id already exists in playlist_exposure, if it doesn't, I have a code that will just insert all data needed but if the id already exists, all I need is just to update the column(current_exposures) and add the new total exposures..

I have no problem in inserting data but I don't know how to update it.

Here's a sample of my select statement:

Expand|Select|Wrap|Line Numbers
  1. SELECT (((SUM(total_uptime.total_on_hours))*(60*60))/10)/(taxi.slots_taken + 3) AS exposure FROM total_uptime
  2.         JOIN playlist_terminal
  3.         ON total_uptime.terminal_id = playlist_terminal.terminal_id
  4.         JOIN taxi
  5.         ON taxi.terminal_id = playlist_terminal.terminal_id
  6.         JOIN playlists
  7.         ON playlists.playlist_id = '608'
  8.         WHERE playlist_terminal.userid = '10' AND playlists.userid = '10' AND total_uptime.start_time BETWEEN  '2014-09-03' AND '2014-09-05'
  9.         GROUP BY playlist_terminal.ref_number
and my idea of updating the table is:

Expand|Select|Wrap|Line Numbers
  1. UPDATE playlist_exposures set current_exposure = (SELECT (((SUM(total_uptime.total_on_hours))*(60*60))/10)/(taxi.slots_taken + 3) AS exposure FROM total_uptime
  2.         JOIN playlist_terminal
  3.         ON total_uptime.terminal_id = playlist_terminal.terminal_id
  4.         JOIN taxi
  5.         ON taxi.terminal_id = playlist_terminal.terminal_id
  6.         JOIN playlists
  7.         ON playlists.playlist_id = '608'
  8.         WHERE playlist_terminal.userid = '10' AND playlists.userid = '10' AND total_uptime.start_time BETWEEN  '2014-09-03' AND '2014-09-05'
  9.         GROUP BY playlist_terminal.ref_number)
  10. WHERE playlist_id = '608'
I already tried this but unfortunately, it doesn't work.

If anyone could help me, give suggestions or at least guide me. It would be a big help and I would really appreciate it. Thank you in advance!

Cheers!
Sep 15 '14 #1
2 2362
Did you try this? Instead to use select statement directly in sql statement, return a value from select statement first and then use the value in update statement.

I think it really works.
Sep 16 '14 #2
maeC
5
I don't know why I didn't thought of that. Thank you for the suggestion.
Sep 16 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mark S. | last post by:
Hi, I have a weird UPDATE sequence I want to perform. The customer does not want to use INSERT and DELETE. My issue is that there are multiple Mat_Class, but I do not wish to hard code each one...
1
by: avinash | last post by:
hi myself avi i am developing one appliacaion in which i am using vb 6 as front end, adodb as database library and sql sever 7 as backend. i want to update one table for which i required data from...
15
by: grunar | last post by:
After some thought on what I need in a Python ORM (multiple primary keys, complex joins, case statements etc.), and after having built these libraries for other un-named languages, I decided to...
4
by: Dave [Hawk-Systems] | last post by:
have a data table that records entries by date(unix timestamp) and customer number. each custnum will have several entries showing a running ledger type snapshot. we have the need to get the most...
1
by: vj | last post by:
How to Update multiple tables in a single SQL update Statement? Is there any way out? vj.
1
by: Mike Preston | last post by:
This isn't working: Update Table1 set Field1 = (Select Mid(TextVariable,10) from Table2 where (Table2.OtherVariable = "WhatIKnowIsThere") and (mid(TextVariable,1,9)="FIRSTNINE")) where...
2
jamesd0142
by: jamesd0142 | last post by:
Hi this is wiered but i can't think how to do it... I have a fully populated table (call it table1) which looks: col01 | col02 | col03 | col04 | col05 | col06 |......... Now what i want is...
1
by: themightyrhino | last post by:
I'm writing a process to perform multiple updates on a main table from information stored in different component reports. As you can see from the below, I'm using a select query to base the update...
12
by: lewelljo | last post by:
Hello Everyone & please excuse my ignorance. I am fairley new to .net and newer to SQL. The below code gives me an exception telling me that it is an invalid column name. It's taking the input...
2
by: amitsukte | last post by:
Hi Everyone how should i update multiple columns of a table from another table... Suppose I have table A and B and having four columns each table A(col1,col2,col3,col4) B(col1,col2,col3,col4) ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.