I've two tables: one for transacctions and something for bills. It may be aprpoved transactions that creates a bill. There might be NOT approved transactions that does not creates a bill.
However , I must print the data of both tables, however is not possible to ascertain if you will see (or otherwise) a bill.
Some reps fields come from:
Transactions: service_bill, auth_number, UserId ... Bill: UserId, ...
After I perform the query:
SELECT * FROM transactions, bill WHERE MONTH(date) = '09' AND YEAR(date) = 2011 (...) AND bill.userId = transactions.userId (...) ORDER BY id_transaction
Basically use that question, I'll print the data that matchs the "userId", but however , it will not print the transactions without bills -because, you don´t come with an userId to complement-
Basically relax the where, it'll print several occasions exactly the same information :/
In the finish, I wish to print all the details -without repetitions- as well as in the NOT produced bills, once the transactions is displayed the balance info is NULL or something like that like this.
Any idea to resolve this?
You need to make use of a LEFT Participate in this situation. This returns all rows in the first table together with any matches based in the second table. Any unmatched rows will return NULL values for that posts from the second table.
SELECT * FROM transactions t LEFT JOIN bill b ON t.userId = b.userId WHERE MONTH(date) = '09' AND YEAR(date) = 2011 (...) ORDER BY t.id_transaction