Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT from Two Tables 2

Status
Not open for further replies.

RRoswell

Programmer
Sep 26, 2006
24
Hi,

I have two tables, a cart table and an account table.

I need to see if an item is in either table with one Select statement. The item should never be in both tables at the same time.

I try this but it's not working:

SELECT a.item, c.item FROM accounts a, cart c WHERE a.acct = '$item' OR c.acct = '$item'

Any ideas?

Gracias.
 
Use a union query:
Code:
SELECT item FROM accounts WHERE acct='$item'
UNION
SELECT item FROM cart WHERE acct='$item'

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
The item should never be in both tables at the same time.
should never? or will never?


if you want to see whether the item actually is in both tables, change UNION to UNION ALL


r937.com | rudy.ca
 
r937,

That was some star-worthy advice.

Each item is unique, so it should only appear in the cart while the user is buying the product, or in the account table after it has been confirmed that they paid for the item.

I can see some items slipping through the cracks and getting stuck in the cart table at the beginning until I get the system working right.

Your advice will probably help me track those discrepancies down.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top