MySQL Forums
Forum List  »  Newbie

Inner Join of 3 tables
Posted by: James Hartwell
Date: August 20, 2014 03:59PM

Hello All,

I am going back and attempting to set up a join statement for my tables, but I seem to be failing terribly at it. Here is what I have so far:

mysql> show Columns from description;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| scpart | varchar(11) | NO | PRI | | |
| name | longtext | NO | | | |
+--------+-------------+------+-----+---------+-------+

mysql> show Columns from manufacturer;
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| scpart | varchar(11) | NO | PRI | | |
| manufacturer | longtext | NO | | | |
| manupart | longtext | NO | | | |
+--------------+-------------+------+-----+---------+-------+

mysql> show Columns from part_number;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| scpart | varchar(11) | NO | PRI | | |
+--------+-------------+------+-----+---------+-------+

Ultimately, I am trying to get the query to output something like this:

+-------------+----------------------------------+--------------+-------------+
| scpart | name | manufacturer | manupart |
+-------------+----------------------------------+--------------+-------------+
| XYZ-0123-45 | Super Duper Hard Drive | Western Gate | SC1234567XX |
+-------------+----------------------------------+--------------+-------------+


So far I have been unsuccessful with my query:

Select part_number.scpart, name
FROM partnumber inner join description ON
part_number.scpart = description.scpart
Union
Select part_number.scpart, manufacturer, manupart
FROM part_number inner join manufacturer ON part_number.scpart = manufacturer.scpart;

Error executing explain
('The used SELECT statements have a different number of columns', 1222)

Is there something I'm missing?

Options: ReplyQuote


Subject
Written By
Posted
Inner Join of 3 tables
August 20, 2014 03:59PM
August 20, 2014 09:41PM
August 21, 2014 08:11AM
August 21, 2014 11:52AM
August 21, 2014 01:24AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.