0

Will try to explain as best i can :)

I have 2 tables

Cloths tables (many) to Question Tables (one)

I want to show questions to a cloth item. Which works fine

What i am trying to understand, is that if a cloth item is removed from the database, the question will not sure up

as i have this as my sql command

"SELECT contact.id, contact.name, contact.email, contact.comments,contact.type, contact.stockid, contact.date ,
                      stock.stockid, stock.name ,stock.mainimage,  stock.price FROM contact,stock
                      where contact.stockid = stock.stockid
                      and contact.type ='ques'"

This will display the question related to stock item, what i am trying to get my brain around, how would i do it for example

If no stock.stock id, display question, but with a header, "this question is for a stock item that has been removed.

Any guidance would be great.

Many thanks

1

2 Answers 2

1

You need a LEFT JOIN for this. Try the following query:

"SELECT contact.id, contact.name, contact.email, contact.comments,
    contact.type, contact.stockid, contact.date
    stock.name, stock.mainimage,  stock.price
FROM contact
LEFT JOIN stock ON (stock.stockid = contact.stockid)
WHERE contact.type ='ques'"

When you are fetching the rows, if name, mainimage or price fields are NULL, that means there are no stocks for that contact.

Sign up to request clarification or add additional context in comments.

Comments

0
FROM `contact`

LEFT JOIN `stock` ON `stock`.`id` = `contact`.`stockid`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.