Jump to content

Using a Where By in a JOIN that ins't exact


cooldude832

Recommended Posts

I have a table Pictures that store the gallery the picture belongs to via a single field

Gallery_ID

which has values of

G_123

E_421

G_123

E_41

etc.

I have a query of

Select Events.EventID as Event_ID , Events.EventName as Name , Events.Start_Date as Start_date , Events.End_Date as End_date , Events.ModifiedDate as Date_mod , Events.CreatedDate as Date_created , Events.Summary as Summary , Admins.Email as Creator , COUNT(Pictures.PicID) as Pic_Count from `Events` left join `Admins` on (Admins.AdminID = Events.CreatorID) left join `Pictures` on (Pictures.Gallery_ID = Events.EventID) Where Events.Start_Date >= '2008-01-27 7:02:43' and Events.Active = '1' Group By Events.EventID Order By Start_Date DESC

Now my issue is the part in the joining of pictures

(Pictures.Gallery_ID = Events.EventID)

It needs to really be

(Pictures.Gallery_ID = "E_".Events.EventID)

However I am not sure how to do the connotation in mysql like that. 

Link to comment
Share on other sites

I tried to do

Select Events.EventID as Event_ID , Events.EventName as Name , Events.Start_Date as Start_date , Events.End_Date as End_date , 

Events.ModifiedDate as Date_mod , Events.CreatedDate as Date_created , Events.Summary as Summary , Admins.Email as Creator , 

CONCAT('E_',Events.EVENTID) as E_search , COUNT(Pictures.PicID) as Pic_Count from `Events` left join `Admins` on (Admins.AdminID = 

Events.CreatorID) left join `Pictures` on (Pictures.Gallery_ID = E_search) Where Events.Start_Date >= '2008-01-27 7:09:45' and Events.Active = '1' 

Group By Events.EventID Order By Start_Date DESC

but get an unknown field E_Search in the clause

 

 

 

When I take the join out in phpmyadmin the field E_Search is E_EVENTID as I want, but how do I use it as criteria for the join?

Link to comment
Share on other sites

solved it I just had to CONCAT in the JOIN caluse

Select Events.EventID as Event_ID , Events.EventName as Name , Events.Start_Date as Start_date , Events.End_Date as End_date , 
Events.ModifiedDate as Date_mod , Events.CreatedDate as Date_created , Events.Summary as Summary , Admins.Email as Creator , 
COUNT(Pictures.PicID) as Pic_Count from `Events` left join `Admins` on (Admins.AdminID = Events.CreatorID) left join `Pictures` on (Pictures.Gallery_ID 
= CONCAT('E_',Events.EventID)) Where Events.Start_Date >= '2008-01-27 7:26:28' and Events.Active = '1' Group By Events.EventID Order By 
Start_Date DESC

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.