IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SQLite Discussion :

SELECT ne fonctionne qu'avec LIKE


Sujet :

SQLite

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    61
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 61
    Points : 34
    Points
    34
    Par défaut SELECT ne fonctionne qu'avec LIKE
    Bonjour,

    Soit une table toute bête : 2 colonnes de nombres (integer)
    Si je fais un :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SELECT * FROM matable WHERE col1 = '45454'
    j'obtiens un résultat vide.

    Par contre un
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SELECT * FROM matable WHERE col1 LIKE '45454'
    me retourne le bon enregistrement.

    J'ai rajouté un index, une primarykey mais pas d'effet.

    Je ne comprend pas pourquoi ça ne marche pas avec "=".

    Ca ne serait pas très gênant si je ne voulais récupérer les enregistrements absents de cette table.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SELECT num1 FROM maTable1 WHERE num1 NOT IN (SELECT col1 FROM matable)
    Or là dans les résultats reçus, j'ai des enregistrements pourtant présents dans la table...

    Des idées ? Merci !

  2. #2
    Membre éprouvé
    Homme Profil pro
    Chef de projets retraité
    Inscrit en
    Juillet 2011
    Messages
    420
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Cher (Centre)

    Informations professionnelles :
    Activité : Chef de projets retraité
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2011
    Messages : 420
    Points : 1 102
    Points
    1 102
    Par défaut
    Bonjour,

    as tu essayé de supprimer les apostrophes?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SELECT * FROM matable WHERE col1 = 45454
    Ceci fera une comparaison entière au lieu d'un comparaison caractères.

    sinon postes le DDL de ta table et un jeu d'essai.

    Cordialement

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    61
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 61
    Points : 34
    Points
    34
    Par défaut
    Oui, j'avais d'abord testé sans.

    Voilà un extrait de dump. Pour les "Primary Key" elles n'ont pas d'utilité je pense.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
     
    CREATE TABLE "BDTFXTAXREF"(
    	"numnomenbdtfx" Integer,
    	"numnomentaxref" Integer,
    PRIMARY KEY ( "numnomenbdtfx","numnomentaxref" ) );
     
     
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 1,79313 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 2,79314 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 3,79315 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 4,79316 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 5,79317 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 6,79318 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 74929,79319 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 12,79320 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 13,79321 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 14,79322 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 15,79323 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 16,79324 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 17,79325 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 18,79326 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 7,79327 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 19,79328 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 20,79329 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 21,79330 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 22,79331 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 23,79332 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 24,79333 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 25,79334 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 26,79335 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 28,79336 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 29,79337 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 30,79338 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 31,79339 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 32,79340 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 33,79341 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 34,79342 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 35,79343 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 9,79344 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 36,79345 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 39,79346 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 40,79347 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 41,79348 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 42,79349 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 8,79350 );
    INSERT INTO "BDTFXTAXREF"("numnomenbdtfx","numnomentaxref") VALUES ( 43,79351 );

  4. #4
    Modérateur
    Avatar de sevyc64
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2007
    Messages
    10 192
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 10 192
    Points : 28 075
    Points
    28 075
    Par défaut
    Sans les apostrophes et sans le LIKE, ça doit marcher. Sinon le souci est ailleurs !

    A noter qu'il ne faut pas mettre col1, mais le vrai nom de la colonne pour que ça marche
    --- Sevyc64 ---

    Parce que le partage est notre force, la connaissance sera notre victoire

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    61
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 61
    Points : 34
    Points
    34
    Par défaut
    Ben justement ça marche pas.

    Ma vraie requête (dans mon premier post, j'avais changé les noms des tables et colonnes) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SELECT * FROM BDTFXTAXREF WHERE numnomenbdtfx=35
    ne renvoie rien. C'est bien pour ça que je ne comprend pas ce qui coince...

    Ah, je viens d'insérer un enregistrement pour test, et lui peut être trouvé avec un "="

    La table a été remplie depuis un import de fichier, le problème doit se situer à ce niveau (pourtant le fichier d'origine est "propre").
    Je vais tenter de recréer la table d'une autre méthode.

    [Edit]
    EN recréant la table et en précisant "Not null" pour les colonnes, ça marche !
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    CREATE TABLE "BDTFXTAXREF"(
    	"numnomentaxref" Integer NOT NULL,
    	"numnomenbdtfx" Integer NOT NULL )

  6. #6
    Membre éprouvé
    Homme Profil pro
    Chef de projets retraité
    Inscrit en
    Juillet 2011
    Messages
    420
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Cher (Centre)

    Informations professionnelles :
    Activité : Chef de projets retraité
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2011
    Messages : 420
    Points : 1 102
    Points
    1 102
    Par défaut
    Avec le DDL que tu as posté et la bonne requête, j'obtiens bien un résultat => c'est en effet probablement du à la méthode d'importation.

    Donc résolu?

  7. #7
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    61
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 61
    Points : 34
    Points
    34
    Par défaut
    J'ai refait un test : en important mes données avec mon logiciel, quand j'essaye de trier une colonne, c'est un tri "alphabétique" qui a lieu :
    alors qu'avec un import manuel, le tri est correct.

    Pourquoi je ne sais pas ! Mais l'important est que ça marche désormais. Donc résolu.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. select sur 2 tables avec Like
    Par serna dans le forum Débuter
    Réponses: 16
    Dernier message: 05/01/2010, 09h36
  2. LIKE qui ne fonctionne pas avec une espace
    Par CinePhil dans le forum Requêtes
    Réponses: 2
    Dernier message: 15/10/2008, 16h46
  3. Réponses: 4
    Dernier message: 06/11/2007, 09h58
  4. [MySQL] Requête SELECT avec LIKE : pb de CASSE
    Par pcayrol dans le forum PHP & Base de données
    Réponses: 1
    Dernier message: 05/06/2007, 20h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo