Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

combine two queries

Posted on 2011-03-04
4
Medium Priority
?
287 Views
Last Modified: 2012-05-11
I have to combine php and sql.  I want to have one sql statement

this is a for loop that checks to see if $productid is in addonitems

select productid from addonitems where productid=$productid



update orderitems set addon=1 where productid=$productid
0
Comment
Question by:rgb192
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
derekkromm earned 1000 total points
ID: 35037231
update orderitems set addon=1 where productid=$productid and exists (select 1 from addonitems where productid = $productid)
0
 
LVL 18

Expert Comment

by:sventhan
ID: 35037251
update t
set addon = 1
from orderitems t
where productid=$productid
0
 
LVL 18

Assisted Solution

by:sventhan
sventhan earned 1000 total points
ID: 35037356
added the exists

update t
set addon = 1
from orderitems t
where productid=$productid
and exists (select 1 from addonitems where productid = $productid)
0
 

Author Closing Comment

by:rgb192
ID: 35038174
thanks
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question