How to combine MYSQL query from different table ?

Hi,

I would like to request an assistant.

I have the following tables :

Table 1 name : transactions
column name : id,ownerid,date,ta,nta,st,tax,seed,debcred,tt

Table 2 name : client_invoices
column name : id,status


Current query :

$res_select = "SELECT id,ownerid,date,ta,nta,st,tax,seed,debcred,tt FROM transactions WHERE date >= $startStamp AND date <= $EndStamp and st != '' order by id";

I would like to combine a condition to the above query as follows :

WHERE transactions.seed  = client_invoices.id WHERE client_invoices.status = 1


I have tried the following, but seems not working :

$res_select = "SELECT transactions.id, transactions.ownerid, transactions.date, transactions.ta, transactions.nta, transactions.st, transactions.tax, transactions.seed, transactions.debcred, transactions.tt, client_invoices.id
                  FROM transactions
                  RIGHT JOIN client_invoices
                  ON transactions.seed = client_invoices.id
                  WHERE (transactions.date >= $startStamp AND transactions.date <= $EndStamp)
                  AND transactions.seed = client_invoices.id WHERE client_invoices.status = 1
                  AND transactions.st != '' ORDER BY transactions.id";


Appreciates anybody can help me with this query.

                  
Thank you.
LVL 2
Shamsul KamalJunior TechAsked:
Who is Participating?

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

x
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.

Ray PaseurCommented:
Maybe the two WHERE clauses are part of the problem?  MySQL usually creates some kind of error message that you can find if the SELECT query returns FALSE.  Obviously I cannot test this because I do not have your data set, but this is what I might try.
$res_select = "SELECT transactions.id, transactions.ownerid, transactions.date, transactions.ta, transactions.nta, transactions.st, transactions.tax, transactions.seed, transactions.debcred, transactions.tt, client_invoices.id
                  FROM transactions
                  RIGHT JOIN client_invoices
                  ON transactions.seed = client_invoices.id
                  WHERE (transactions.date >= $startStamp AND transactions.date <= $EndStamp)
                  AND transactions.seed = client_invoices.id AND client_invoices.status = 1
                  AND transactions.st != '' ORDER BY transactions.id";

Open in new window

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
arnoldCommented:
While both tables have id, those are not related
You need to provide is ownerid in the transaction I a client Id?

In your first query you are missing a comparison value you have st != <missing comparison value/variable> Followed by  order by
This will generate an error when ran.
Shamsul KamalJunior TechAuthor Commented:
Spot On.... Thank you.
Ray PaseurCommented:
Thanks for the points and thanks for using E-E, ~Ray
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
PHP

From novice to tech pro — start learning today.