Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Mysql join..Simple, yet confused...
Old 02-11-2012, 09:37 AM Mysql join..Simple, yet confused...
Brian07002's Avatar
Defies a Status

Posts: 2,301
Name: ...
Location: ...
Trades: 1
Hi,

I would like to display data from two different mySQL tables which appears to work ok, except for one major problem...I am getting too many results...I have had only a quick explaination on how the joins work so far, but from what I have seen, I will need one of several different types of joining applied to the query..I don't know which one I need to use though. Here's the query in question that I am working with that gives too many results (more than what I expected)

PHP Code:
$query="SELECT table1.column, table2.column FROM table1, table2"
Also, how would I handle a situation if both columns had the same name in the database of course their tables are different, but I have that situation as well.

PHP Code:
$query="SELECT table1.title, table2.title FROM table1, table2"
Thank you in advance!
_Brian_
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 02-11-2012 at 09:56 AM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-11-2012, 09:47 AM Re: Mysql join..Simple, yet confused...
NullPointer's Avatar
Will Code for Food

Posts: 2,883
Name: Matt
Location: Irvine, CA
Trades: 0
http://dev.mysql.com/doc/refman/5.0/en/join.html

What you're probably looking for is a left join.
Code:
SELECT table1.column, table2.column FROM table1 LEFT JOIN table2 ON (table1.foo = table2.bar);
For example, if I had a table people and a table jobs:
Code:
people:
id | name | job

jobs:
id | title
The following query would get every person's name and job title:

Code:
SELECT people.name as name, jobs.title as title FROM people LEFT JOIN jobs ON (people.job = jobs.id);
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 02-11-2012 at 09:59 AM..
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-11-2012, 09:58 AM Re: Mysql join..Simple, yet confused...
Brian07002's Avatar
Defies a Status

Posts: 2,301
Name: ...
Location: ...
Trades: 1
Thank you Matt, I will have a look later, I have to leave for work now. I will try it tonight.

Thanks again!
-Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Mysql join..Simple, yet confused...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15961 seconds with 11 queries