Web Analytics Made Easy -
StatCounter joining tables in sql - CodingForum

Announcement

Collapse
No announcement yet.

joining tables in sql

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • joining tables in sql

    I have built an sql script that connects to one tables. however I want to connect now to 2, this is what I had

    $query = "SELECT * FROM artists WHERE ID = ".stripslashes($ID);


    how do I connect to 2 tables, I know about foreign fields, its just the sql Im not sure about, if someone could post some example ive been googling it for ages, with no success.
    Jason Morjaria

  • #2
    Is this for a MySQL database?
    Spookster
    CodingForum Supreme Overlord
    All Hail Spookster

    Comment


    • #3
      i have a similar question, and yes it is for a mySQL database.

      i have two tables with different information. both tables have dates and event titles though. how can i create a new table, on the fly, with the date fields and title fields from both?
      "There is more than one way to do it."

      Comment


      • #4
        yes it is mysql, do you have any ideas, I want to join the tables with a simple ID. I think I can do the join part, (although add an exmaple for me to look at) but its putting it in the php page as I showed you above,
        Jason Morjaria

        Comment


        • #5
          Don't you think you should have posted this in the MySQL forum?

          I'll move it there...
          Spookster
          CodingForum Supreme Overlord
          All Hail Spookster

          Comment


          • #6
            Haahhhh. Fresh meat !!
            I want to join the tables with a simple ID. I think I can do the join part, (although add an exmaple for me to look at) but its putting it in the php page as I showed you above,
            $query = "SELECT artists.var1, artists.var2, artists.var3 FROM artists INNER JOIN table2 ON artists.joiningfieldfromartists=table2.joiningfieldfromtable2= WHERE ID = ".stripslashes($ID);

            ==> the italic parts need to be replaced by your atual column and tablenames. Post the real table-design if you need to exact query for your situation.
            Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

            Comment


            • #7
              Originally posted by dswimboy
              i have a similar question, and yes it is for a mySQL database.

              i have two tables with different information. both tables have dates and event titles though. how can i create a new table, on the fly, with the date fields and title fields from both?
              Please, do not hijack a thread. Start a new one for your problem, which is totaly different from the original subject + you need to give more info. Like : do both source-tables have the same number of records? does the new table need to have 2 tiltle and 2 date fields, or just one of each so that bothe sourcetables columns could be merged?
              Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

              Comment

              Working...
              X