php tutorial(joins)

Upload: ali-rameez

Post on 07-Jul-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/18/2019 Php Tutorial(Joins)

    1/7

    PHP Tutorial (Joins) 

     Joins Defnitions

    What is oreign key

    How To set Foreign key

    INNER join example

    EFT join !"ery

    RI#HT join !"ery F$ join !"ery

     Joins: INNER J%IN& The 'ost (ommon Type o Join is INNER J%IN) It ret"rns all the

    rows rom the m"ltiple ta*les where the join +on,ition met) EFT J%IN& it ret"rns all rows rom let ta*le -ta*le./ with mat+hing rows in the

    right ta*le -ta*le 0/) The res"lt is N$ on right si,e i there is no mat+h RI#HT J%IN& It ret"rns all the rows rom right ta*le -ta*le 0/ with the mat+hing

    rows in let ta*le -ta*le./) The res"lt is N$ on let si,e i there is no mat+h) F$ J%IN& F"ll o"ter joins ret"rns all rows rom let ta*le -ta*le./ an, rom

    right ta*le-ta*le0/F$ %$TER J%IN +om*ines the res"lt o let ta*le an, right ta*le)

    What is foreign key

    Foreign key is a fel, -or +olle+tion o fel,s/ in one ta*le that "ni!"elyi,entifes a row o another ta*le) In simpler wor,s1 the oreign key is ,efne,

    in a se+on, ta*le1 *"t it reers to the primary key in the frst ta*le)

    How to set foreign key #o to 2H2mya,min

    (hange the type o ta*le to InnoD3 i alrea,y not set

    4iew the str"+t"re o the ta*le whi+h will ha5e a oreign key) 'ake the

    reeren+ing fel, an INDE6 Now +ome *a+k to str"+t"re 5iew an, +li+k Relation 5iew)

  • 8/18/2019 Php Tutorial(Joins)

    2/7

    7ET $2 the oreign key)

    (li+k on sa5e

    INNER join with exa!le First o all I +reate, two ta*le in the ,ata *ase -+"stomer an, +"stomer8o/ 7et "p oreign key -+"stomer8i,/ in ta*le -+"stomer8o/)

    (reate, two orms or ,ata insertion in ta*les

  • 8/18/2019 Php Tutorial(Joins)

    3/7

    (o,e or +"stomer or,er orm9meta http:e!"i5;

  • 8/18/2019 Php Tutorial(Joins)

    4/7

    9,i5 i,; Go8,ate;G82%7To8,ate>i -G+on;;tr"e /

    K==e+ho

  • 8/18/2019 Php Tutorial(Joins)

    5/7

    mys!li8!"ery-G+on1

  • 8/18/2019 Php Tutorial(Joins)

    6/7

      9tr@  9th@("stomer ID9=th@  9th@("stomer Name9=th@  9th@(onta+t Name9=th@  9th@(ity9=th@

      9th@(o"ntry9=th@

      9th@ %r,er Date9=th@9th@ %r,er No9=th@

      9=tr@9=thea,@

      9t*o,y@  9php while- Grow ; mys!li8et+h8array- Gsele+tRes / /K

     @9tr@9t,@9php e+ho Grow+"stomer8i,> @9=t,@ 9t,@9php e+ho Grow+"stomer8name> @9=t,@ 9t,@9php e+ho Grow+onta+t8name>@9=t,@

     9t,@9php e+ho Grow+ity> @9=t,@ 9t,@9php e+ho Grow+o"ntry>@9=t,@ 9t,@9php e+ho Growo8,ate>@9=t,@ 9t,@9php e+ho Growo8No>@9=t,@9=tr@9=t*o,y@

     9php L @ 9=ta*le@9=*o,y@9=html@

    7a5e this fle with name +"stomer8or,er8,etail)php

  • 8/18/2019 Php Tutorial(Joins)

    7/7

    INNER J"IN #ueryGsele+t7P ; 7EE(T

    +"stomer)+"stomer8i,1+"stomer)+"stomer8name1+"stomer)+onta

    +t8name1+"stomer)+ity1 +"stomer)+o"ntry1

    +"stomer8o)o8No1+"stomer8o)o8,ate FR%' +"stomer INNER

     J%IN +"stomer8o %N

    +"stomer)+"stomer8i,;+"stomer8o)+"stomer8i,>

    $E%T J"IN #ueryGsele+t7P ; 7EE(T

    +"stomer)+"stomer8name1+"stomer)+onta+t8name1+"stomer)+ity1

    +"stomer)+o"ntry FR%' +"stomer EFT J%IN +"stomer8o %N

    +"stomer)+"stomer8i,;+"stomer8o)+"stomer8i,>

    RI&HT J"IN #uery

    Gsele+t7P ; 7EE(T

    +"stomer)+"stomer8name1+"stomer)+onta+t8name1+"stomer)+ity1

    +"stomer)+o"ntry 1+"stomer8o)o8No FR%' +"stomer RI#HT

     J%IN +"stomer8o %N

    +"stomer)+"stomer8i,;+"stomer8o)+"stomer8i,>

    %'$$ J"IN #uery

    Gsele+t7P ; 7EE(T U FR%' +"stomer EFT %$TER J%IN

    +"stomer8o %N +"stomer)+"stomer8i, ;+"stomer8o)+"stomer8i,

    $NI%N M7EE(T U FR%' +"stomer EFT %$TER J%IN +"stomer8o %N

    +"stomer)+"stomer8i, ;+"stomer8o)+"stomer8i,V>