Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Save a Query as a View issue

Save a Query as a View issue

Scheduled Pinned Locked Moved Database
helpquestiondatabase
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    john_berman
    wrote on last edited by
    #1

    How can I convert this query to a view The query work but i get error message if I try to save as a view - the errors talk about duplicate names ?

    SELECT DISTINCT
    b.event_id AS a,
    b.user_ID AS a,
    b.date AS a,
    b.Time AS a
    FROM quadrantids2017 AS a
    JOIN quadrantids2017 AS b
    WHERE a.`date` = b.`date`

    AND a.user_ID != b.user_ID
    AND time_to_sec(a.`Time`) - time_to_sec(b.`Time`) BETWEEN -30 AND 30

    Thanks in advance John B

    Richard DeemingR 1 Reply Last reply
    0
    • J john_berman

      How can I convert this query to a view The query work but i get error message if I try to save as a view - the errors talk about duplicate names ?

      SELECT DISTINCT
      b.event_id AS a,
      b.user_ID AS a,
      b.date AS a,
      b.Time AS a
      FROM quadrantids2017 AS a
      JOIN quadrantids2017 AS b
      WHERE a.`date` = b.`date`

      AND a.user_ID != b.user_ID
      AND time_to_sec(a.`Time`) - time_to_sec(b.`Time`) BETWEEN -30 AND 30

      Thanks in advance John B

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Every column in a view needs to have a unique name. You've given all four columns the alias "a", which is obviously not unique. Just remove the four As a alias from the SELECT part of the query, and you should be able to create a view.

      SELECT DISTINCT
      b.event_id,
      b.user_ID,
      b.date,
      b.Time
      FROM
      quadrantids2017 AS a
      JOIN quadrantids2017 AS b
      WHERE
      a.`date` = b.`date`
      AND
      a.user_ID != b.user_ID
      AND
      time_to_sec(a.`Time`) - time_to_sec(b.`Time`) BETWEEN -30 AND 30

      Alternatively, give each column a unique alias.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups