Page 1 of 1

Trying to join 2 tables in mysql-Help!

Posted: Sat Jul 10, 2010 10:25 am
by canadian_angel
I am trying to join two tables and havent been very successful, can anyone please help!
The two tables are joke and author; I need to get the authors name and email address in the joke table! The database is ijdb;


mysql> USE ijdb;
Database changed
mysql> SELECT LEFT(joketext, 20), authorid FROM joke;
+----------------------+----------+
| LEFT(joketext, 20) | authorid |
+----------------------+----------+
| Why did the chicken | 0 |
| What is a cows favor | 0 |
+----------------------+----------+
2 rows in set (0.02 sec)

mysql> SELECT * FROM author;
+----+-----------------+-------------------+
| id | name | email |
+----+-----------------+-------------------+
| 1 | fredl | fredl@home.ca |
| 2 | john adams | johna@hotmail.com |
| 3 | tim horton | timmy@home.ca |
| 4 | colonel sanders | colonels@home.ca |
+----+-----------------+-------------------+
4 rows in set (0.00 sec)

mysql> SELECT LEFT(joketext, 20), name, email
-> FROM joke, author WHERE authorid = author.id;
Empty set (0.00 sec)

Re: Trying to join 2 tables in mysql-Help!

Posted: Sat Jul 10, 2010 11:48 am
by AbraCadaver
Maybe because all of the authorid in the joke table are 0, but there is no id of 0 in the author table.

Re: Trying to join 2 tables in mysql-Help!

Posted: Sat Jul 10, 2010 3:25 pm
by canadian_angel
I know I am not sure how I got the zeros, in any case I still need to get the authors email addresses and names in the joke table and I dont know how?

Re: Trying to join 2 tables in mysql-Help!

Posted: Sat Jul 10, 2010 4:27 pm
by AbraCadaver
canadian_angel wrote:I know I am not sure how I got the zeros, in any case I still need to get the authors email addresses and names in the joke table and I dont know how?
Well, the authid needs to be equal to some id or you can't. How could you, there is nothing in common?