• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

query

I have two tables.
orders table and ship table
For orders table,
ordernum
------------
1
2
3
4

For ship table,
ordernum        tracking_num
------------
1                           t1    
3                           t3


I want to have the Result looks like
----------------
ordernum      tracking_num
-----------      ----------------
1                         t1
2
3                         t3
4

if i do like,

select orders(*), ship(*)
from orders, ship
where orders.ordernum = ship.ordernum

it only displays two results.

but i want to display all of ordernum with tracking_num(it's ok even though it is null)

how can i do that??
0
bbvic
Asked:
bbvic
1 Solution
 
tdterryCommented:
You're looking for a LEFT JOIN.  That will include all fields from the LEFT table whether they match the right table or not.

SELECT *
FROM orders LEFT JOIN ship
    ON (orders.order_num = ship.ordernum)
0
 
bbvicAuthor Commented:
thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now