MySQL query to JOIN tables based on column values -
i've got 2 tables. 1 part numbers, hardware names, , type , other locations of hardware has locations of specific bins contain hardware. bins don't have specific number have unique names. second table has location of hardware , bin may change on time. , i'm trying create mysql query combine data in new table outputted comma separated file.
table 1 contents
part number | name | type ------------+---------------+--------------- 0 | none | not applicable 25 | name1 | type1 150 | name2 | type2
table 2 contents
date | bin | part number | event | location | location ---------+------+--------------+----------+-------------+--------------- 1/1/2013 | bin1 | 0 | arrive | location1 | none 1/2/2013 | none | 25 | arrive | location2 | none 1/2/2013 | none | 150 | relocate | location3 | location2
the final output of query should like:
date | bin | part number | part name | type | event | location | location ---------+------+-------------+-----------+----------------+----------+-------------+-------------- 1/1/2013 | bin1 | 0 | none | not applicable | arrive | location1 | none 1/2/2013 | none | 25 | name1 | type1 | arrive | location2 | none 1/2/2013 | none | 150 | name2 | type2 | relocate | location2 | location2
try this:
select * `table1` inner join `table2` on (`table1`.`part number`=`table2`.`part number`)
to make query better, want define columns wanted returned instead of *
Comments
Post a Comment