tags:

views:

60

answers:

1

I am needing to connect two tables by id then access any of the data from either of them inside a foreach loop.

I've never done any LEFT JOINS or anything so I'm not sure how to start.

The first table named "sys_acl_levels_members" looks like this:

IDMember
IDLevel
DateStarts
DateExpires
TransactionID 

The other table "Profiles" has many more colums but here are the first few:

ID
NickName
Email

I need help with writing an SQL to gather all this information, then some ways to access it inside of a foreach loop.

For example if I wanted to get "DateStarts"," DateExpires" From "sys_acl_levels_members" and "NickName" FROM "Profiles" WHERE IDLevel = ID.

+3  A: 
SELECT acl.DateStarts, acl.DateExpires
FROM sys_acl_levels_members acl
LEFT JOIN Profiles p
ON p.ID = acl.IDLevel
Thomas O
Sorry I'm a lil lost. I've only worked with simpler queries. Can you explain this a little?
whatshakin
What are LEFT JOIN and ON doing?
whatshakin
LEFT JOIN joins two tables together, ON is like the "WHERE" condition. Read it like this: "fetch the row from Profiles WHERE p.ID is equal to IDLevel; and fetch it only once. If there is no result, regard the fields from this row as NULL." (that is, return a result even if the LEFT JOIN condition does not match.)
Thomas O