Jump to content
Sign in to follow this  
abdelelbouhy

Select from two tables

Recommended Posts

Hi guys,

i have two tables products and deleted_products i want to select products_id from the two tables where the field suspend = 1 but there's no relationship between the tables in other words i want all the products_id from the tables where suspend = 1 but the products_id in table one doesn't match produtcs_id in table 2 the only relationship i can find is the suspend in both tables is 1

 

 

my query string is like that

 

select p.products_id as PID, dp.products_id AS PDID FROM products p, deleted_products dp WHERE p.suspend = dp.suspend and p.suspend = 1

 

it return zero result but the two tables have products with suspend = 1

 

thanx

Edited by abdelelbouhy

Share this post


Link to post
Share on other sites

No relationship (between your tables) = no join with sql. However, you can select both tables with two different queries and combine their results with PHP.

Edited by niche

Share this post


Link to post
Share on other sites

Use a union, that's what they're for.

 

SELECT product_id FROM table1 WHERE suspend=1 UNION SELECT product_id FROM table2 WHERE suspend=1

  • Like 1

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...