TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 11-24-2010, 07:46 PM   #1 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default JOIN query

I'm trying join 2 tables and think I require a LEFT join as all rows in table1 are required but struggling to handle the rules associated with table2. Looking for some help/guidance. My tables are basically:

TABLE1
userid. user
1. Mr Smith
2. Mr Davis
3. Mrs Jackson

TABLE2
imageid. Main_image. userid
23. Y 1
24. N. 1
25. Y. 2

I'm looking for a query that will return every row in table1 then rows associated in table2 assuming the main_image flag is set to Y.

I've done a left join but when append AND main_image = Y i lose rows from table1 that don't match that criteria I.e. User 3. How can I pull all users from table1 then pull in all main_images from table2?

Hope u get the gist having trouble easily documenting this as typing it on an iPhone but any help greatly appreciated.
captainmerton is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
What is good MySQL practice? Aaron MySQL & Databases 7 11-23-2012 10:56 AM
Query With a C# Variable?‏ StevenF The Lounge 5 12-08-2008 05:32 AM
UNION query doesn't work...? Dave MySQL & Databases 0 09-20-2008 07:22 PM
Tables joining other Tables? Orc MySQL & Databases 6 02-09-2008 09:42 PM
Mysql problem, most likely related to left join Village Idiot MySQL & Databases 6 01-04-2008 06:09 AM


All times are GMT. The time now is 10:47 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design