Précédent   Forum des professionnels en informatique > Bases de données > MySQL > Requêtes
Requêtes Forum d'entraide sur les requêtes MySQL
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 15/07/2011, 14h39   #1
Invité de passage
 
Inscription : janvier 2009
Messages : 5
Détails du profil
Informations forums :
Inscription : janvier 2009
Messages : 5
Points : 2
Points : 2
Par défaut requêtes imbriquées, encore !

Je voudrais lire dans la table "NacPort", les champs "NACPort_IsPartOf", "NACPort_MifIndex" qualifiés "NACPort_IsLearn" = 1 , et dans la table Itf, retrouver le champ "Itf_MifDescr " de ("NACPort_IsPartOf", "NACPort_MifIndex").

Les 3 requêtes ci dessous peuvent elles être réalisées en une requête imbriquée ?
Code :
1
2
3
SELECT * 
FROM NACPort 
WHERE NACPort_IsLearn = 1;
+-------------+------------------+------------------+-----------------+-------------------+---------------------+---------------------+
| NACPort_uid | NACPort_MifIndex | NACPort_IsPartOf | NACPort_IsLearn | NACPort_IsDeLearn | NACPort_AuthDate    | NACPort_ForbDate    |
+-------------+------------------+------------------+-----------------+-------------------+---------------------+---------------------+
|          32 |            10024 | mgth03  |               1 |                 0 | 2011-07-06 15:26:35 | 2000-01-01 01:01:01 |
|          31 |            10001 | mgth99  |               1 |                 0 | 2011-07-04 17:25:29 | 2000-01-01 01:01:01 |
+-------------+------------------+------------------+-----------------+-------------------+---------------------+---------------------+
Code :
1
2
3
SELECT Itf_uid,Itf_MifIndex,Itf_MifName,Itf_MifDescr,Itf_IsPartOf 
FROM Itf 
WHERE Itf_IsPartOf = "mgth03" ;
+---------+--------------+-------------+--------------------+-----------------+
| Itf_uid | Itf_MifIndex | Itf_MifName | Itf_MifDescr       | Itf_IsPartOf    |
+---------+--------------+-------------+--------------------+-----------------+
|  229423 |        10012 | Fa0/12      | FastEthernet0/12   | mgth03 |
|  229421 |        10010 | Fa0/10      | FastEthernet0/10   | mgth03 |
|  229438 |        10501 | Nu0         | Null0              | mgth03 |
|  229435 |        10024 | Fa0/24      | FastEthernet0/24   | mgth03 |
|  229434 |        10023 | Fa0/23      | FastEthernet0/23   | mgth03 |
|  229433 |        10022 | Fa0/22      | FastEthernet0/22   | mgth03 |
|  229432 |        10021 | Fa0/21      | FastEthernet0/21   | mgth03 |
|  229431 |        10020 | Fa0/20      | FastEthernet0/20   | mgth03 |
|  229430 |        10019 | Fa0/19      | FastEthernet0/19   | mgth03 |
|  229429 |        10018 | Fa0/18      | FastEthernet0/18   | mgth03 |
|  229428 |        10017 | Fa0/17      | FastEthernet0/17   | mgth03 |
|  229427 |        10016 | Fa0/16      | FastEthernet0/16   | mgth03 |
|  229425 |        10014 | Fa0/14      | FastEthernet0/14   | mgth03 |
|  229424 |        10013 | Fa0/13      | FastEthernet0/13   | mgth03 |
|  229422 |        10011 | Fa0/11      | FastEthernet0/11   | mgth03 |
|  229420 |        10009 | Fa0/9       | FastEthernet0/9    | mgth03 |
|  229419 |        10008 | Fa0/8       | FastEthernet0/8    | mgth03 |
|  229418 |        10007 | Fa0/7       | FastEthernet0/7    | mgth03 |
|  229417 |        10006 | Fa0/6       | FastEthernet0/6    | mgth03 |
|  229414 |        10003 | Fa0/3       | FastEthernet0/3    | mgth03 |
|  229413 |        10002 | Fa0/2       | FastEthernet0/2    | mgth03 |
|  229412 |        10001 | Fa0/1       | FastEthernet0/1    | mgth03 |
|  229411 |            1 | Vl1         | Vlan1              | mgth03 |
|  229437 |        10102 | Gi0/2       | GigabitEthernet0/2 | mgth03 |
|  229436 |        10101 | Gi0/1       | GigabitEthernet0/1 | mgth03 |
|  229416 |        10005 | Fa0/5       | FastEthernet0/5    | mgth03 |
|  229426 |        10015 | Fa0/15      | FastEthernet0/15   | mgth03 |
|  229415 |        10004 | Fa0/4       | FastEthernet0/4    | mgth03 |
|  229439 |          233 | Vl233       | Vlan233            | mgth03|
+---------+--------------+-------------+--------------------+-----------------+
29 rows in set (0.01 sec)
Code :
1
2
3
SELECT Itf_uid,Itf_MifIndex,Itf_MifName,Itf_MifDescr,Itf_IsPartOf 
FROM Itf 
WHERE Itf_IsPartOf = "mgth03" AND Itf_MifIndex = 10024 ;
+---------+--------------+-------------+------------------+-----------------+
| Itf_uid | Itf_MifIndex | Itf_MifName | Itf_MifDescr     | Itf_IsPartOf    |
+---------+--------------+-------------+------------------+-----------------+
|  229435 |        10024 | Fa0/24      | FastEthernet0/24 | mgth03|
+---------+--------------+-------------+------------------+-----------------+
1 row in set (0.00 sec)
Code :
1
2
3
4
SELECT Itf_uid,Itf_MifIndex,Itf_MifName,Itf_MifDescr,Itf_IsPartOf 
FROM Itf 
WHERE Itf_IsPartOf = "mgth99" 
AND Itf_MifIndex = 10001 ;
+---------+--------------+-------------+-----------------+-----------------+
| Itf_uid | Itf_MifIndex | Itf_MifName | Itf_MifDescr    | Itf_IsPartOf    |
+---------+--------------+-------------+-----------------+-----------------+
|  229412 |        10001 | Fa0/1       | FastEthernet0/1 | mgth99 |
+---------+--------------+-------------+-----------------+-----------------+
1 row in set (0.01 sec)
jur466 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/07/2011, 15h07   #2
ced
Rédacteur/Modérateur

 
Avatar de ced
 
Homme Cédric Duprez
Inscription : avril 2002
Messages : 3 823
Détails du profil
Informations personnelles :
Nom : Homme Cédric Duprez
Âge : 36
Localisation : France, Loiret (Centre)

Informations professionnelles :
Secteur : Agroalimentaire - Agriculture

Informations forums :
Inscription : avril 2002
Messages : 3 823
Points : 6 440
Points : 6 440
Bonjour,

Une petite jointure ne peut-elle pas suffire ? Pourquoi vouloir imbriquer ?

Code :
1
2
3
4
SELECT NACPort_IsPartOf, NACPort_MifIndex, Itf_MifDescr
FROM NACPort p
INNER JOIN Itf i ON p.NACPort_MifIndex = i.Itf_MifIndex AND p.NACPort_IsPartOf = i.Itf_IsPartOf
WHERE NACPort_IsLearn = 1;
__________________
Rédacteur / Modérateur SGBD
Mes tutoriels et la FAQ MySQL

----------------------------------------------------
Pensez aux balises code et au tag
Je ne réponds pas aux questions techniques par message privé, les forums sont là pour ça
ced est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/07/2011, 15h23   #3
Invité de passage
 
Inscription : janvier 2009
Messages : 5
Détails du profil
Informations forums :
Inscription : janvier 2009
Messages : 5
Points : 2
Points : 2
Bon, après moultes essais, cette requêtes semble donner le bon résultat :

Code :
1
2
3
4
5
SELECT Itf_MifName , Itf_MifDescr, Itf_IsPartOf 
FROM Itf,NACPort 
WHERE NACPort_IsLearn = 1 
AND Itf_IsPartOf = NACPort_IsPartOf 
AND Itf_MifIndex = NACPort_MifIndex ;
+-------------+------------------+-----------------+
| Itf_MifName | Itf_MifDescr     | Itf_IsPartOf    |
+-------------+------------------+-----------------+
| Fa0/24      | FastEthernet0/24 | mgth03 |
| Fa0/1       | FastEthernet0/1  | mgth99|
+-------------+------------------+-----------------+
2 rows in set (0.00 sec)
jur466 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/07/2011, 15h39   #4
ced
Rédacteur/Modérateur

 
Avatar de ced
 
Homme Cédric Duprez
Inscription : avril 2002
Messages : 3 823
Détails du profil
Informations personnelles :
Nom : Homme Cédric Duprez
Âge : 36
Localisation : France, Loiret (Centre)

Informations professionnelles :
Secteur : Agroalimentaire - Agriculture

Informations forums :
Inscription : avril 2002
Messages : 3 823
Points : 6 440
Points : 6 440
Euh, j'voudrais pas avoir l'air, mais j'ai écrit exactement la même chose, avec des jointures normalisée, ce qui est préférable .

?
__________________
Rédacteur / Modérateur SGBD
Mes tutoriels et la FAQ MySQL

----------------------------------------------------
Pensez aux balises code et au tag
Je ne réponds pas aux questions techniques par message privé, les forums sont là pour ça
ced est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/07/2011, 15h49   #5
Invité de passage
 
Inscription : janvier 2009
Messages : 5
Détails du profil
Informations forums :
Inscription : janvier 2009
Messages : 5
Points : 2
Points : 2
Citation:
Envoyé par ced Voir le message
Euh, j'voudrais pas avoir l'air, mais j'ai écrit exactement la même chose, avec des jointures normalisée, ce qui est préférable .

?
Désolé, j'étais reparti dans mes requêtes et n'avais pas vu votre réponse.
Merci en tout cas.
JM
jur466 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 22h05.


 
 
 
 
Partenaires

Hébergement Web