links between tables

0
$sql = "SELECT * FROM Inscricao WHERE al_id = ".$_GET['idc'];
$sql = "SELECT * FROM Aluno WHERE al_id = ".$_GET['idc'];
$sql = "SELECT * FROM EncarregadoDeEducacao WHERE ee_id = ee_id.inscricao where al_id = ".$_GET['idc'];

tables:

CREATE TABLE IF NOT EXISTS 'Inscricao' (
 'insc_id'                      int(4) unsigned Not Null AUTO_INCREMENT,
 'al_id'                        int(4) Not Null DEFAULT '0',
 'ee_id'                        int(4) Not Null DEFAULT '0',
 'obs_desc'                     varchar(250)    Not Null DEFAULT 'Sem observacoes',
 'prof_nome'                    varchar(50) Not Null DEFAULT '',
 'insc_data'                    DATE Not Null DEFAULT '00-00-0000', 
  PRIMARY KEY ('insc_id')
) ENGINE=myisam DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS 'Aluno' (
 'al_id'                        int(4) unsigned Not Null AUTO_INCREMENT,
 'al_nome'                      varchar(50) Not Null DEFAULT '',
 'al_idade'                     int(2)  Not Null DEFAULT '0',   
 'al_data'                      DATE Not Null DEFAULT '00-00-0000', 
 'al_morada'                    varchar(80) Not Null DEFAULT '',    
 'al_escolaridade'              int(2)  Not Null DEFAULT '0',   
 'al_nomepai'                   varchar(50) Not Null DEFAULT '',    
 'al_nomemae'                   varchar(50) Not Null DEFAULT '',    
 'al_nomeensino'                varchar(50) Not Null DEFAULT '',    
 'al_localensino'               varchar(80) Not Null DEFAULT '',    
 'al_img'                       varchar(32) NOT NULL DEFAULT '',
 'ocupacao'                     varchar(250)    Not Null DEFAULT 'sem ocupacao de tempos livres',
 'tra_simnao'                   varchar(250)    Not Null DEFAULT 'nao',
 'tra_desc'                     varchar(250)    Not Null DEFAULT 'Sem Transporte',
  PRIMARY KEY ('al_id')
) ENGINE=myisam DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS 'EncarregadoDeEducacao' (
 'ee_id'                        int(4) unsigned Not Null AUTO_INCREMENT,
 'ee_nome'                      varchar(50) Not Null DEFAULT '',    
 'ee_parentesco'                varchar(10) Not Null DEFAULT '',    
 'ee_localtrab'                 varchar(80) Not Null DEFAULT '',    
 'ee_telemovel'                 int(9)  Not Null DEFAULT 0,
 'ee_telefone'                  int(9)  Not Null DEFAULT 0,
 'ee_urgencia'                  int(9)  Not Null DEFAULT 0,
 'ee_email'                     varchar(50) Not Null DEFAULT '',
  PRIMARY KEY ('ee_id')
) ENGINE=myisam DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;

I need to select data from the 3 tables to list the data of the complete enrollment of the student (data of the 3 tables) for example inscription 1 with student 2 in charge of education 5 and the respective data of each of the 3.

If I try to put it in 3 select I know the error I wanted to know how to do what I want without error, thanks.

    
asked by anonymous 14.04.2015 / 12:32

2 answers

0

You have to join the keys with the table based on what you have in the Registration table:

    select *
    from Inscricoes i
    inner join Aluno a on a.al_id = i.al_id
    inner join EncarregadoDeEducacao e on e.ee_id = i.ee_id
    WHERE a.al_id = SEU_PARAMETRO
    /*
        Aqui você pode continuar o where, order by e etc...
    */
    
17.04.2015 / 14:09
0

Thank you for the help, when I saw your answer had already done so:

$sql = "SELECT * FROM Inscricao, Aluno, EncarregadoDeEducacao WHERE Inscricao.al_id = Aluno.al_id AND EncarregadoDeEducacao.ee_id = Inscricao.ee_id AND Inscricao.al_id = ".$_GET['idc'];

I think you're both be

    
21.04.2015 / 12:39