Question

select * from deliveries, remittance

table 'deliveries' has 10 records while table 'remittance' has none. This query returns no results. what I want is mysql to return the 10 records from table 'deliveries'. please help me.

this is a sample table

deliveries -> trans_number from to

remittance -> trans_number from to

Was it helpful?

Solution 2

try something like

select * from deliveries
left join remittance
on remittance.id = deliveries.remittance_id

It will bring all data from deliveries and matching data from remittance

UPDATE:

If you want to show records in any case if any table has records then you are looking for FULL OUTER JOIN

But since FULL OUTER JOIN is not supported in try this query

SELECT * FROM deliveries
LEFT JOIN remittance ON remittance.id = deliveries.remittance_id
UNION
SELECT * FROM deliveries
RIGHT JOIN remittance ON remittance.id = deliveries.remittance_id

OTHER TIPS

You might need to use LEFT JOIN:

select deliveries.* 
from deliveries
left join remittance on ... -- put a join condition here.

This will return all the records from the deliveries table even if no matching rows found in the other table.

If you used INNER JOIN it won't return any rows, since the other table is empty. But it will give you only the rows from the deliveries which match the condition.

try this

     select d.* , r.* from deliveries d , remittance r

You need to give some criteria so that mysql can display the result for the tables..Like Join

SELECT * FROM deliveries 
LEFT JOIN remittance 
ON remittance.id = deliveries.remittance_id

Try This

select d.* from deliveries d left join remittance r
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top