php - How to make a join statement between multi table to one table? -


first, have 4 table , columns such

  1. feeds (id, type, type_id)
  2. feeds_normals (id, type, content)
  3. feeds_links (id, type, title, link)
  4. feeds_youtubes (id, type, title, link, description, image)
  5. feeds_photos (id, type, link)

the table of "feeds type_id" match/linkup "id" of normals, links, youtubes, photos

and

the table of "feeds type" using identified table should joined

for example:

feeds: id: 1, type: "normal", type_id: 1 id: 2, type: "link", type_id: 1  feeds_normals: id: 1, type: "normal", content: "this test"  feeds_links: id: 1, type: "link", title: "this title", link: "http://yahoo.com" 

result:

id: 1, type: "normal", content: "this test", title: null, link: null id: 2, type: "link", content: null, title: "this title", link: "http://yahoo.com" 

finally

in case, how write sql statement?

something wrong here, may example or actual data. here how super-type/subtype model looks like:

alt text

the matching data-example be:

feeds: feedid: 1, type: "normal" feedid: 2, type: "link"  feeds_normals: feedid: 1, content: "this test"  feeds_links: feedid: 2, title: "this title", link: "http://yahoo.com" 

note feedid in subtype table matches 1 in super-type. type field in subtype tables optional -- allows check constraint enforce types not mixed in subtype table.

the query like:

select       f.feedid     , n.content      normalscontent     , y.title        youtubetitle     , y.link         youtubelink     , y.description  youtubedescription     , y.image        youtueimage     , k.title        linkstitle     , k.link         linkslink feeds              f left join feeds_normals n on n.feedid = f.feedid left join feeds_links   k on k.feedid = f.feedid left join feeds_youtube y on y.feedid = f.feedid ; 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -