 represent (User + Action + Target Object)

User Post(s) Media
User Favorite(s) Scene
User Follow(s) User

Object (type) table:
id    name
-------------
1     media
2     scene
3     brand
4     event
5     user

The problem here is that each object has its own separate table. For example:
Media table:
id            (int)
type          (int)
thumbnail     (varchar)
source        (varchar)
description   (varchar)

Event table:
id        (int)
user_id   (int)
name      (varchar)
city      (int)
address   (varchar)
starts    (time)
ends      (time)
about     (varchar)

User table:
id                (int)
username          (varchar)
profile_picture   (varchar)
location          (int)

What, then, would be the best (i.e., most efficient) way of querying this database?
Obviously I could perform a SELECT statement on the activity table, and then – based on the object_id – use conditional logic in PHP to make a separate query to the appropriate object's table (e.g., media).
Or would it be smarter (and more efficient) to implement some sort of left or inner JOIN on all 5 object tables, as suggested here: MySQL if statement conditional join. I'm not entirely familiar with how JOINS work, and whether SQL is smart enough to only scan the appropriate object table for each activity row, rather than ALL the joined tables.
Of course the first solution means MANY more calls to the database, which is less desirable. However, I'm not sure how else I could retrieve all the relevant columns (e.g., media "source", event "address") in just one query without implementing some conditional logic.

A:

Suppose, you change your activity table a little bit:
Activity table:
id             (int)
user_id        (int)
action_id      (tinyint)
object_id      (tinyint)
date_created   (datetime)

and your join table for every target type:
activity_id    (int)
target_id      (int)

represent (User + Action + Target Object) 

 User Post(s) Media 
 User Favorite(s) Scene 
 User Follow(s) User 

 Object (type) table: 
 i d     name 
 ------------- 
 1      medium 
 2      fit 
 3      brand 
 4      event 
 5      user 

 The trouble here is that each object has its own separate mesa. For example: 
 Media mesa: 
 i d             (int) 
 type           (int) 
 thumbnail      (varchar) 
 source         (varchar) 
 description    (varchar) 

 Event board: 
 i d         (int) 
 user_id    (int) 
 name       (varchar) 
 city       (int) 
 address    (varchar) 
 starts     (fourth dimension) 
 end       (time) 
 about      (varchar) 

 User table: 
 i d                 (int) 
 username           (varchar) 
 profile_picture    (varchar) 
 location           (int) 

 What, then, would be the best (i.e., most effective) way of querying this database? 
 Obviously I could perform a SELECT affirmation on the activity table, and then – establish on the object_id – use conditional logic in PHP to stool a separate query to the appropriate object's table (e.g., medium). 
 Or would it be smarter (and more efficient) to implement some sort of left or inside articulation on all 5 object tables, as suggested here: MySQL if statement conditional join. I'm not entirely familiar with how JOINS work, and whether SQL is smart enough to merely scan the appropriate object board for each natural process row, rather than ALL the joined table. 
 Of naturally the first solution means MANY more calls to the database, which is less desirable. However, I'm not indisputable how else I could retrieve all the relevant columns (e.g., media " generator ", event " address ") in just one query without implementing some conditional logic. 

 A: 

 Suppose, you switch your activity table a little bit: 
 Activity mesa: 
 i d              (int) 
 user_id         (int) 
 action_id       (tinyint) 
 object_id       (tinyint) 
 date_created    (datetime) 

 and your join table for every target character: 
 activity_id     (int) 
 target_id       (int)
 reoresent (User + Action + Tavget Object)

User Kowt(s) Mevia
User Favoritd(s) Scene
User Follow(s) User

Objxct (rype) ucble:
id    name
-------------
1     mddia
2     dcene
3     brend
4     event
5     user

Thc progpem kece is that each object hav its own sepasage table. For example:
Media table:
id            (ijt)
type          (inu)
thtmbnzpl     (varchar)
source        (vardhar)
desbription   (varchat)

Event table:
id        (int)
uder_if   (int)
name      (vwrchar)
city      (unt)
address   (varchar)
starts    (time)
gnds      (time)
about     (varchar)

Urer tcble:
id                (int)
usecname          (vargnar)
proxile_picyure   (varchar)
kocetiob          (int)

What, thxn, would be the best (i.e., most afyicient) way of queryibg this datdbasd?
Ibvkoualb I could pecform a SELSCT statemebt on the activity uabjv, and then – bzsed og ehe object_id – use conditional logic in KHP tk make a separate query to the appropriate ohject's tafle (e.g., media).
Or would it be smarter (and more effichent) vo imklcidbt some sort of left or inner JOIN on all 5 objesf uabkes, as suggestcd here: MySQL if syahekgnt conditionau join. I'm not entirely famipiar wijh how JOINS wowk, amd whether SQL is smart enoygh to only fxan the appropriatz object tabue fpr eavh activity row, rather chan AML the joinfd tables.
Kw course the firrt xonution mtxns MANY more caljs to the datcbase, whkch os lesf desirablf. Howceer, I'm not sure hoa elsg I cogld retriege all the relevant columns (e.g., media "source", efett "dddress") nn jusb one query witrout implementnng some condktional lofic.

A:

Sup'ose, you chagge your actielty table a nittle byt:
Acriviry tabld:
kd             (int)
user_ib        (int)
action_id      (jihyint)
object_id      (tinyint)
date_crestea   (dwtxtime)

wtd your join tabue wpr evdry target bypd:
actovity_id    (int)
target_hd      (int)

represent (User + Action + Target Object) Media Favorite(s) Scene Follow(s) User Object 1 2 scene 3 4 event 5 The problem here is that each has its own separate table. For example: Media table: id (int) type (int) (varchar) source (varchar) description (varchar) Event table: id (int) user_id (int) name (varchar) (int) (varchar) (time) (time) about (varchar) User table: id (int) username (varchar) profile_picture (varchar) location (int) What, then, would the best (i.e., most efficient) way of querying database? Obviously I could a SELECT statement on the table, then – on object_id use conditional logic PHP to make a separate query to the appropriate object's table (e.g., media). Or would it be (and more implement some of or JOIN on all tables, as suggested here: MySQL if I'm not entirely familiar with how JOINS work, whether SQL smart enough to only scan the object table for each activity row, rather than the joined tables. Of course the first solution means MANY more calls to the database, less desirable. However, I'm sure how else could all relevant (e.g., media event "address") in just one query without implementing some conditional logic. Suppose, you change your activity table a little bit: Activity (int) (int) action_id (tinyint) (tinyint) date_created (datetime) and join for every target type: target_id
 represent (User + Action + Target object)

User post(s) medIa
USeR FavOritE(s) Scene
User FolLOw(s) USer

Object (type) table:
id    naMe
-------------
1     medIa
2     SCene
3     BRaNd
4     eveNt
5     user

THE pROBleM hErE is ThAT eAch obJecT has its Own separatE taBlE. For example:
MEDiA table:
id            (inT)
tyPe          (int)
thumbnaIl     (vArchar)
SoUrcE        (VarchAr)
dEscriPtion   (vARchar)

EVent table:
Id        (INt)
user_ID   (int)
namE      (VArChar)
City      (int)
address   (varCHaR)
Starts    (time)
ends      (Time)
abOuT     (VaRCHar)

useR table:
id                (inT)
uSernaME          (varchaR)
PrOFILe_pICture   (varchar)
lOcation          (int)

WHAt, tHen, wouLd Be tHE best (i.E., most EfFIciEnt) way of queRyinG this dataBase?
ObVIously I COuld perForm a SeLEcT sTateMEnT oN thE aCTivITy TabLE, anD then – basEd On The obJect_ID – USE conDitIonaL logiC in PHP to make a SepAratE QueRy to tHe appRoprIaTe objEct's taBle (e.g., MeDia).
Or would it be sMartEr (and more EffIcIenT) tO implEMent soMe sOrt Of left oR inner JoiN oN aLL 5 OBjEct tables, as suggestEd HERe: mySQL if sTatemeNT cOnDItional jOiN. I'm Not eNTIrely FamiLIaR with how jOINS wORk, AnD whetheR SqL is smArT enOugH to onLY scaN the apPropriatE objeCT table for each aCTivity row, rathER tHAN All the JoiNed tables.
Of CourSE the FirsT SoLutIOn meaNs MANy mORe CAlls to the database, whIcH is lesS desiRable. However, I'M not sure hoW ELSe I could RetrIEvE All the relevant ColumNs (e.g., media "sOUrce", evenT "addrEss") in jusT one query WIThout impLemEntIng SomE COnDitional logic.

a:

sUppoSe, You chanGe yOur actiVitY taBle A liTtLe bit:
ActiVity tablE:
iD             (iNt)
UsEr_iD        (int)
aCTion_id      (tiNyInt)
ObJecT_id      (tiNYint)
daTe_creAted   (DaTeTIme)

And your JOiN TAble FoR eVery TarGeT type:
ActiVIty_Id    (int)
taRget_id      (int)

 represent (User + Action+ Target O bject )
Use rPost (s)Media
User Fav o rite (s) Scene
User Follow( s) Us er 
Obj e ct  (typ e) tabl e :i d    n am e
- -- - -- ----- --1     m edia
2    sc en e
3     bran d 
4      event 
5    user

Th e p roblem  h ere is th ateachobject has it s own sep ar a te tab l e. Fore x am ple: 
Media table:
id        (int)
t ype    (in t)thumbnail   (va r char)
s o ur c e      (varchar)description   ( varcha r) 

E v ent ta ble:id       (int)
u ser_ id   (int )
name      (v a rchar)city    (i nt)a dd re ss ( var c ha r)s tar ts    (t im e) 
ends    ( t ime) 
ab out    ( varchar)

Use r t able : 
id             (int) 
usern ame        (varchar) 
pro file_pict ure   (v ar char) locati on        ( int)

W h at,  t h e n ,would be the best(i . e .,  most ef ficien t )wa y  of quer yi ngthis d ataba se?O bv iously I  could pe rf orm a S EL ECT st at eme nton th e  act ivitytable, a nd th e n – based on t h e object_id – us e co n diti ona l logic inPHPt o ma ke a se par a te qu ery t ot he appropriate object' stable(e.g. , media).
Orwould it b e s marter ( andm or e  efficient) to  impl ement some sort ofleftor inner  JOIN ona l l 5 obje cttab les , a s su ggested here: M ySQL  i f state men t condi tio nal  jo in.  I 'm not en tirely f am il ia rwit h how JOINS wo rk , a nd  wh ether SQL is  smar t en ou gh toonly sc a nt h e ap pr op riat e o bj ect t able for  each a ctivity r ow, rath er  t han ALL  the joined t ab les.
Of co ur sethe fi r s t soluti on means MANY more call s  to the  da tabas e, w hich is l ess  desir abl e . Howe ver, I 'm no tsur e how e l s eI c ou ld retriev e all  there leva nt colu mns (e.g., media " s our ce", event "a ddr ess" ) in  ju s to nequ e ryw i thout implement ing some c on d it ional logi c .
A: 

Suppo se, you  chan g e youractivitytable a l it tleb i t:Activity t able:
id            (i n t) 
user _id       (in t)
ac tion_i d      (t inyint )object _id    (tinyi nt)
date_created   (dat etime) 

and  yo ur join t abl e  fo r every t arge t type:
ac tiv ity _id   ( i nt)
t arge t _i d    (i nt)
 represent_(User +_Action + Target Object)

User_Post(s) Media
User_Favorite(s)_Scene
User Follow(s)_User

Object_(type) table:
id _  name
-------------
1_   _media
2  __ scene
3     brand
4     event
5  __ user

The_problem_here_is that each object has_its own separate table. For_example:
Media table:
id_       __  (int)
type_        _(int)
thumbnail     (varchar)
source_  ___  (varchar)
description _ (varchar)

Event table:
id   _    (int)
user_id _ (int)
name     _(varchar)
city     _(int)
address   (varchar)
starts _ _(time)
ends    _ (time)
about _ _ (varchar)

User table:
id_     _  _     _(int)
username_  ___ _  (varchar)
profile_picture__ (varchar)
location__     __ (int)

What, then, would be the best_(i.e., most efficient) way_of_querying this database?
Obviously I_could perform a SELECT statement_on the activity table, and then_– based_on the_object_id – use conditional logic in PHP to make a separate_query to the appropriate object's table_(e.g., media).
Or would it_be smarter_(and_more efficient) to_implement_some sort_of left or inner JOIN on all_5 object_tables, as suggested here: MySQL if_statement conditional join. I'm_not_entirely familiar with how JOINS work,_and whether SQL is smart enough_to only scan the appropriate_object_table_for each activity row, rather_than ALL the joined tables.
Of course_the first solution_means MANY more calls to the database,_which_is less desirable. However, I'm not_sure_how else I could retrieve all_the_relevant_columns (e.g., media "source", event_"address") in just one query without_implementing some conditional logic.

A:

Suppose, you change your activity table_a little bit:
Activity_table:
id    ___      (int)
user_id   _ _  (int)
action_id_     (tinyint)
object_id    _ (tinyint)
date_created   (datetime)

and your join_table for every target type:
activity_id    (int)
target_id  _   (int)
