Jump to content

[SOLVED] Cross Table Reference Query Problems


roddyguy

Recommended Posts

I have two tables: PRODUCTS and PATTERN BINDINGS

The PRODUCT_ID is the field they have in common.

So sometimes a Product may have more than one record associated within the PATTERN BINDINGS table.

Using a search form I have built, queries are made to the Database to find PATTERN BINDING records that are associated with the PRODUCTS.

 

Thus using the "OR" situation for searching works fine.

IE:

"SELECT p.products_id FROM products p, pattern_bindings pb WHERE p.products_id = pb.products_id AND (pb.pc_id = '5' OR pb.pc_id = '32')"

 

But using the "AND", obviously does not.

IE:

"SELECT p.products_id FROM products p, pattern_bindings pb WHERE p.products_id = pb.products_id AND (pb.pc_id = '5' AND pb.pc_id = '32')"

 

In other words, I am trying to come up with a way to look for cases where the Product has a record for both patterns. (A more filtered search)

 

The only way that I figured out how to do this -- is by using sub-queries.

IE:

select p.products_id from products p, pattern_bindings pb where p.products_id = pb.products_id and p.products_id IN (select p.products_id from products p, pattern_bindings pb where p.products_status = '1' and p.products_id = pb.products_id and (pb.pc_id = '31' or pb.pc_id = '999999999')) and p.products_id IN (select p.products_id from products p, pattern_bindings pb where p.products_status = '1' and p.products_id = pb.products_id and (pb.pc_id = '31' or pb.pc_id = '999999999')) GROUP BY p.products_id

 

 

As you can imagine, this takes a while to process. Slow moving.

 

I tried many JOIN Query solutions, but could not get any to work.

 

Any ideas?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.