Solved

combine two queries

Posted on 2011-03-04
4
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
derekkromm earned 250 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 250 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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