Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6882191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:13:23+00:00 2026-05-27T05:13:23+00:00

I tried to make a SQL query with a nested SELECT on the SAME

  • 0

I tried to make a SQL query with a nested SELECT on the SAME table (UID in the table are polymorphic).

The problem is that my nested SELECT returns NULL always.

Here is the query :

SELECT
    Ent.UID,
    Measurement.MeasurementClass AS Type,
    Substation.TG8000_Name AS Station,
    SUBSTRING(Measurement.TG8000_Name,1,5) AS Travee,
    SUBSTRING(Measurement.TG8000_Name,6,8) AS Equipement,
    Measurement.ClonedFromMeasurement,
    (SELECT TOP 1 TG8000_Name 
        FROM [BD_Sonel_PTG].[dbo].[Measurement]
        WHERE (UID=Measurement.ClonedFromMeasurement) )  AS Template,
    LongName.LongName AS Description,
    Measurement.MeasurementUnit AS Units,
    MeasurementLimit.LowLimit,
    MeasurementLimit.HighLimit,
    RTU.TG8000_Name AS RTUName,
    RTU.RTUProtocol,
    RTU.Configuration AS RTUConfiguration,
    Telemetry.Address,
    Measurement.DisplayName AS Display,
    REPLACE(Measurement.MeasurementClass,' ','')+':'+REPLACE(Substation.TG8000_Name,' ','')+'.'+REPLACE(Measurement.TG8000_Name,' ','') AS Tren

  FROM EntityName Ent

  LEFT JOIN LongName ON Ent.UID = Longname.UID  /* chaque point possède une description pour une langue donnée */
  LEFT JOIN Measurement ON Ent.UID = Measurement.UID /* chaque point de type measurement possède des infos suppl dansla table Measurement */
  LEFT JOIN Substation ON Measurement.Substation = Substation.UID /* chaque point est lié à l'UID d'une station (Table Substations) */
  LEFT JOIN Telemetry ON Telemetry.DataSourceFor = Ent.UID /* 1 point télémétré est lié à une entrée de Telemetry (DataSourceFor) */
  LEFT JOIN MeasurementLimit ON Ent.UID = MeasurementLimit.UID /* Chaque point de type measurement est lié à des paramètres limites */
  LEFT JOIN RTU ON Telemetry.RTU = RTU.UID /* chaque point télémétré est associé à un l'UID d'un RTU dont les paramètres sont dans la table RTU */
 /* LEFT JOIN EntityName Ent2 ON Ent.UID = Measurement.ClonedFromMeasurement*/

  WHERE Ent.EntityType = 'Measurement'

  ORDER BY Substation.TG8000_Name, Measurement.TG8000_Name;

  GO

When I execute the nested Select with a hardcoded value as 9616, it works !

... (SELECT TOP 1 TG8000_Name 
        FROM [BD_Sonel_PTG].[dbo].[Measurement]
        WHERE (UID='9616') )  AS Template,
...

So I suppose it is the access to Measurement.ClonedFromMeasurement which doesn’t work…

But as you see in the query, I also outputted the value of Measurement.ClonedFromMeasurement to see what in there, and I recieve correctely my value of 9616 (which is changing from line to line).

How can I access to Measurement.ClonedFromMeasurement in my nested query ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:13:24+00:00Added an answer on May 27, 2026 at 5:13 am

    Try doing a self join for this

    (SELECT TOP 1 TG8000_Name
    FROM [BD_Sonel_PTG].[dbo].[Measurement] m1,m2 on
    m1.UID = m2.ClonedFromMeasurement) AS Template
    

    OR

    (SELECT TOP 1 TG8000_Name
    FROM [BD_Sonel_PTG].[dbo].[Measurement] 
    where UID in (select distinct ClonedFromMeasurement from 
    [BD_Sonel_PTG].[dbo].[Measurement]) AS Template
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want make sql query which will insert values from one table to another
I'm trying to make a Teradata SQL query that will return the n -th
I am using multiple joins in a statement and Have tried to make linq-to-SQl
I am trying to make some sort of SQL Query where I only get
I have a simple SQL query, SELECT * FROM phones WHERE manu='$manuf' AND price
I need to create an SQL query to insert some data into a table
I am working on optimizing a SQL query that goes against a very wide
Is it possible in SubSonic to make a query like this SELECT * FROM
I have the following SQL query: select expr1, operator, expr2, count(*) as c from
I'm probably missing something, but I can't make a simple SQL query work. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.