Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

MySql inner join four tables

  • 27-10-2014 7:53pm
    #1
    Closed Accounts Posts: 1,040 ✭✭✭


    Hi I have four tables
    Table 1 : column1= day,column2=time

    Table 2 : column1=rain, column2=temperature

    Table 3: column1=firstinitial, column2=lastinitial

    Table 4: column1=firstinitial, column2=lastinitial

    I am not sure what the statement should say to inner join all four tables (must use inner join)

    SELECT rain,day,time,temperature,firstinitial,lastinitial INNER JOIN ??


Comments

  • Moderators, Computer Games Moderators Posts: 4,282 Mod ✭✭✭✭deconduo


    That question doesn't make much sense. Generally if you are doing joins on tables there needs to be a common column to join on.

    Have a read of this, it should help:

    http://www.w3schools.com/sql/sql_join_inner.asp


  • Closed Accounts Posts: 1,040 ✭✭✭Scrappychimow


    deconduo wrote: »
    That question doesn't make much sense. Generally if you are doing joins on tables there needs to be a common column to join on.

    I know it has me puzzled, any idea of how to join the tables using another form of join or union etc?


  • Moderators, Computer Games Moderators Posts: 4,282 Mod ✭✭✭✭deconduo


    I know it has me puzzled, any idea of how to join the tables using another form of join or union etc?

    Why do you want to do a join on those particular tables, what sort of data are you trying to pull back?


  • Closed Accounts Posts: 1,040 ✭✭✭Scrappychimow


    i made a mistake i dont need to join four tables, but still need to get that data using inner join


  • Closed Accounts Posts: 8,061 ✭✭✭keith16


    deconduo wrote: »
    That question doesn't make much sense. Generally if you are doing joins on tables there needs to be a common column to join on.

    Have a read of this, it should help:

    http://www.w3schools.com/sql/sql_join_inner.asp

    This link is very helpful OP, definitely read it and try the examples using your own data.
    i made a mistake i dont need to join four tables, but still need to get that data using inner join

    The data in your OP bears no relation to what you posted in the word doc...so I think we are all a bit confused.

    Joins are fairly straightforward once you get used to them.

    SELECT

    [Column1]
    ,[Column2]

    etc....

    FROM myfirstable A

    INNER JOIN mysecondtable B

    ON A.Common_Column_Table1 = B.Common_Column_Table2

    A and B are aliases for your tables so MySQL knows which column you are referring to if there are columns in both tables with the same name.

    Have a look at this too. Should help.

    Joins work because you have columns in more than one table that contain the same data / information, so SQL can display information from more than 1 table by linking a common field / column.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 24 el pibe


    It's not looking like an especially useful data model at first glance.

    Traditionally data in and RDBMS is related (hence the term). We usually do this by providing an artificial key an id) but natural keys are fine.
    The data should obviously reflect the real world thing you're trying to model though.

    A join generally follows this relationship between tow tables. In your case, perhaps, between a weather record, a weather type(?) and some sort of person record, twice?

    Could you describe what it is you're trying to achieve, and perhaps definitions of the full tables along with their names?.

    If things were clearer we could help.


Advertisement