Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've got two tables. One with part numbers, hardware names, and type and other with the locations of the hardware that also has locations of specific bins that contain the hardware. The bins don't have a specific number but have unique names. The second table also has the location of the hardware and bin which may change over time. And I'm trying to create a MySQL query that will combine the data in a new table that will be outputted as a 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    | To Location | From 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 the query should look something like:

Date     | Bin  | Part Number | Part Name | Type           | Event    | To Location | From 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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
218 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try this:

SELECT
  *
FROM
  `Table1`
  INNER JOIN `Table2` ON (`Table1`.`Part Number`=`Table2`.`Part Number`)

To make the query better, you would want to define all the columns that you wanted returned instead of *


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...