How to combine 2 mysql query ?


May i know how to combine these 2 mysql query in one go ?

SELECT * FROM tblhosting WHERE nextduedate > nextinvoicedate;

Open in new window

SELECT * FROM tblinvoiceitems INNER JOIN tblinvoices ON tblinvoiceitems.invoiceid = WHERE relid =  'x' AND STATUS =  'unpaid';

Open in new window

relid =  'x'  , x is the "id" in "SELECT * FROM tblhosting"

Both are in the same database but 2 separate table.

If using mysql query is not possible, please help me to construct in PHP query.

Thank you.
Shamsul KamalJunior TechAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jan LouwerensSoftware EngineerCommented:
Try something like:
SELECT * FROM tblhosting, tblinvoices, tblinvoiceitems WHERE
   tblhosting.nextduedate > tblhostingnextinvoicedate AND = tblinvoiceitems.invoiceid AND
   relid = AND
   STATUS = 'unpaid';

Open in new window

You might need to preface the 'relid' and 'STATUS' fields with the table name, if they are ambiguous.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shamsul KamalJunior TechAuthor Commented:

I have tried the following :

SELECT * FROM tblhosting, tblinvoices, tblinvoiceitems WHERE
   tblhosting.nextduedate > tblhosting.nextinvoicedate AND = tblinvoiceitems.invoiceid AND
   tblinvoiceitems.relid = AND
   tblinvoices.status = 'unpaid';

Open in new window

But the output seems wrong.

Can anybody spot the problem and help me ?

Thank you.
NerdsOfTechTechnology ScientistCommented:
This is guesswork unless we have some sample input data and expected output.

 FROM tblinvoiceitems ii
 INNER JOIN tblinvoices i
 ON ii.invoiceid =
 LEFT JOIN tblhosting h
 ON ii.relid =
 h.nextduedate > h.nextinvoicedate AND 
 i.relid =  'x' AND 
 i.STATUS =  'unpaid';

Open in new window

Jan LouwerensSoftware EngineerCommented:
What resolution are your dates stored at? Perhaps the issue is this statement:
tblhosting.nextduedate > tblhosting.nextinvoicedate

Open in new window

Maybe what you need is something like:
tblhosting.nextduedate >= tblhosting.nextinvoicedate

Open in new window

Shamsul KamalJunior TechAuthor Commented:
Thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.