Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 03-03-06
scifind's Avatar
thin[box]king
 
Join Date: Aug 2003
Location: Cambridge
Posts: 1,831
Thanks: 6
Thanked 4 Times in 4 Posts
scifind is an unknown quantity at this point
  MySQL Hell

Having a problem with MySQL;

I have 2 tables and using the following to join them

SELECT * FROM table1,table2 WHERE table1.id=table2.id AND table1.id=$requiredid;

where $requiredid is a vairiable generated by PHP to look up a row.

Table2 has supplimentary info, BUT the existance of table2's info is not required, therefore the condition table1.id=table2.id may be false. BUT I would still like to return the info from table1 (where table1.id=$requiredid).

Can someon please tell me how to join these 2 tables and return all table1's info and table2's if it is available.
__________________
Earn an average of £45 per sale. | New Star Trek Trailer | Looking for Mobile Phone Link Swaps
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-03-06
Chris Clarkson's Avatar
PHP never lies...
 
Join Date: Jul 2003
Location: Glasgow
Posts: 631
Thanks: 3
Thanked 5 Times in 5 Posts
Chris Clarkson is an unknown quantity at this point
SELECT t1.*, t2.info FROM table1 t1 LEFT JOIN table2 t2 ON t1.id=t2.id WHERE t1.id=$requiredid;

As its a left join you should still get info for table 1 even if no results for table 2.

Chris
__________________
sunshine.co.uk - Cheap Holidays, Hotels and Flights on Affiliate Future
email: chris.c [at] sunshine.co.uk
Affiliate Area
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-03-06
scifind's Avatar
thin[box]king
 
Join Date: Aug 2003
Location: Cambridge
Posts: 1,831
Thanks: 6
Thanked 4 Times in 4 Posts
scifind is an unknown quantity at this point
Cheers - fixed it.
__________________
Earn an average of £45 per sale. | New Star Trek Trailer | Looking for Mobile Phone Link Swaps
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Warning using reserved words in MySQL DanielCoe Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 4 21-07-05 07:32 PM
MYSQL loading JohnC Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 1 07-02-05 03:02 PM
Connect to MySql on a remote server? accelerator Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 3 07-01-05 04:54 PM
MS Access & mySQL Frostie Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 5 04-10-03 10:46 AM


Affiliate Marketing RSS Feeds - Contact Us - Affiliate Marketing - Archive - Privacy Statement - Top

Content Relevant URLs by vBSEO 3.2.0 RC7