Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
952 views
in Technique[技术] by (71.8m points)

join - sql query for grouping to avoid double fields

As my title says, I want to make a query to avoid field to display twice but I get errors and I don't know how to do.

Here is my query :

SELECT *  FROM ARCHPOINTS LEFT JOIN (SELECT IdArchRonde FROM ARCHRONDES GROUP BY IdArchRonde) ON ARCHPOINTS.IdRonde = ARCHRONDES.IdArchRonde 
ORDER BY ARCHPOINTS.IDPOINT

I want to select fields from the table archpoints and then make a relation with another table called archrondes to get all points from that table. I succeed in doing that without problems, but the problems is now that I have fields (duration and description) that appears each time on each point and to have them appearing only one time in the beginning, I think I have to do a "group by idarchrondes" but I get errors with my syntax.

If anyone could help me. Thank you in advance

question from:https://stackoverflow.com/questions/66065643/sql-query-for-grouping-to-avoid-double-fields

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'm not sure if you query does what you intend. But to fix the syntax error, you need table aliases:

SELECT * 
FROM ARCHPOINTS ap LEFT JOIN 
    (SELECT IdArchRonde
     FROM ARCHRONDES ar
     GROUP BY IdArchRonde
    ) ar
     ON ap.IdRonde = ar.IdArchRonde 
ORDER BY ap.IDPOINT

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...