SQL astuces

12 articles

Comment interroger les libellés des valeurs autorisées plutôt que les codes dans une requête ?

SELECT champ_de recherche FROM table WHERE champ_de_recherche=<<libelle_champ|valeur_autorisee>> Exemple : RECHERCHE GUIDEE PAR TYPE DE DOCUMENT SELECT biblio.title AS Titre, biblio.author AS Auteur, biblioitems.publicationyear AS Date, items.barcode AS Code_barres, items.itemcallnumber AS Cote FROM items,biblio,biblioitems WHERE items.itype=<<TYPE : |ITYPE>> AND items.biblionumber = […]

Comment extraire les attributs lecteurs?

SELECT borrowers.borrowernumber, borrowers.surname, borrowers.firstname, borrowers.cardnumber, borrower_attributes.code, borrower_attributes.attribute FROM borrowers LEFT JOIN borrower_attributes ON (borrowers.borrowernumber=borrower_attributes.borrowernumber) LEFT JOIN borrower_attribute_types ON (borrower_attribute_types.code=borrower_attributes.code) GROUP BY borrower_attributes.attribute ORDER BY borrowers.surname, borrowers.firstname ASC Résultat :

Comment afficher plusieurs valeurs autorisées dans une même requête (sous-requêtes SELECT)

Exemple pour le module adhérent : SELECT borrowers.cardnumber AS numero_carte, borrowers.surname AS Nom, borrowers.firstname AS Prenom, borrowers.email AS email_principal, borrowers.emailpro AS email_alternatif, borrowers.dateenrolled AS date_inscription, borrowers.dateexpiry AS date_expiration, borrowers.categorycode AS categorie_pret, (SELECT description FROM categories WHERE categorycode=borrowers.categorycode) AS categorie, borrowers.sort1, […]