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
Solved

combine two queries

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change variables in SQL table 6 93
ms sql + top 1 for each customer 3 56
CROSS APPLY 4 56
Email Notifications for SQL 2005 9 35
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 …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 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