Solved

combine two queries

Posted on 2011-03-04
4
271 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 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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to simplify my SQL statement? 14 55
SQL query with cast 38 59
SQL Server Insert where not exists 24 52
SQL- GROUP BY 4 21
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…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

713 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