PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > How to Select
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How to Select

Réponse
 
LinkBack Outils de la discussion
Vieux 05/02/2008, 11h11   #1
Sebastian
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to Select

Hi

I have 2 tables:

[general_libcounty]:
- id_libCounty (PK)
- libCounty_name
- id_libCountry

[general_libtown]:
- id_libTown (PK)
- libTown_name
- id_libCounty (FK)

How to select all counties what don't have any towns in
general_libtown table

Relation:
general_libcounty.id_libCounty=general_libtown.id_ libCounty

Thanks for any

Sebastian
  Réponse avec citation
Vieux 05/02/2008, 11h21   #2
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to Select

On Tue, 05 Feb 2008 11:11:21 +0100, Sebastian <haja.sebastian@gmail.com>
wrote:

> Hi
>
> I have 2 tables:
>
> [general_libcounty]:
> - id_libCounty (PK)
> - libCounty_name
> - id_libCountry
>
> [general_libtown]:
> - id_libTown (PK)
> - libTown_name
> - id_libCounty (FK)
>
> How to select all counties what don't have any towns in
> general_libtown table
>
> Relation:
> general_libcounty.id_libCounty=general_libtown.id_ libCounty


Assuming there's nu NULL allowed in general_libtown.id_libCounty:

SELECT c.id_libCounty
FROM general_libcounty c
LEFT JOIN general_libtown t
ON c.id_libCounty = t.id_libCounty
WHERE t.id_libCounty IS NULL

If there are NULLs in general_libtown.id_libCounty:

SELECT c.id_libCounty, COUNT(t.id_libTown) as countTowns
FROM general_libcounty c
LEFT JOIN general_libtown t
ON c.id_libCounty = t.id_libCounty
GROUP BY c.id_libCounty
HAVING countTowns = 0
--
Rik Wasmus
  Réponse avec citation
Vieux 05/02/2008, 11h34   #3
Sebastian
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to Select

On 5 Lut, 10:21, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
> On Tue, 05 Feb 2008 11:11:21 +0100, Sebastian <haja.sebast...@gmail.com>
> wrote:
>


> Assuming there's nu NULL allowed in general_libtown.id_libCounty:
>
> SELECT c.id_libCounty
> FROM general_libcounty c
> LEFT JOIN general_libtown t
> ON c.id_libCounty = t.id_libCounty
> WHERE t.id_libCounty IS NULL
>
> If there are NULLs in general_libtown.id_libCounty:
>
> SELECT c.id_libCounty, COUNT(t.id_libTown) as countTowns
> FROM general_libcounty c
> LEFT JOIN general_libtown t
> ON c.id_libCounty = t.id_libCounty
> GROUP BY c.id_libCounty
> HAVING countTowns = 0
> --
> Rik Wasmus


Thank you Rik

I made something very the same like you first example

SELECT
general_libcounty.*,
general_libtown.*
FROM
general_libcounty
LEFT OUTER JOIN
general_libtown
ON
general_libcounty.id_libCounty=general_libtown.id_ libCounty
WHERE
general_libtown.id_libTown IS NULL

Sebastian
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h50.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08237 seconds with 11 queries