Ver Mensaje Individual
  #2 (permalink)  
Antiguo 03/07/2014, 01:44
quimfv
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 2 meses
Puntos: 574
Respuesta: duda con consulta multiple

Improvisando....

Código MySQL:
Ver original
  1. SELECT "bd1" bbdd, username, account
  2. FROM bd1.accounts
  3. WHERE bd1.accounts IN (SELECT account
  4.             FROM (
  5.                     SELECT username, account
  6.                         FROM bd1.accounts
  7.                   UNION ALL
  8.                      SELECT username, account
  9.                         FROM bd2.accounts
  10.                   UNION ALL
  11.                      SELECT username, account
  12.                           FROM bd3.accounts
  13.                   UNION ALL
  14.                      SELECT username, account
  15.                          FROM bd4.accounts
  16.                   UNION ALL
  17.                       SELECT username, account
  18.                            FROM bd5.accounts
  19.                    UNION ALL
  20.                          SELECT username, account
  21.                               FROM bd6.accounts
  22.                     ) AS todo
  23.               GROUP BY account
  24.               HAVING COUNT( * ) >1)
  25. SELECT "bd2" bbdd, username, account
  26. FROM bd2.accounts
  27. WHERE bd2.accounts IN (SELECT account
  28.             FROM (
  29.                     SELECT username, account
  30.                         FROM bd1.accounts
  31.                   UNION ALL
  32.                      SELECT username, account
  33.                         FROM bd2.accounts
  34.                   UNION ALL
  35.                      SELECT username, account
  36.                           FROM bd3.accounts
  37.                   UNION ALL
  38.                      SELECT username, account
  39.                          FROM bd4.accounts
  40.                   UNION ALL
  41.                       SELECT username, account
  42.                            FROM bd5.accounts
  43.                    UNION ALL
  44.                          SELECT username, account
  45.                               FROM bd6.accounts
  46.                     ) AS todo
  47.               GROUP BY account
  48.               HAVING COUNT( * ) >1)
  49. ...etc
__________________
Quim
--------------------------------------------------
Ayudar a ayudar es una buena práctica!!! Y da buenos resultados.