I have Two Tables, from one table I want to select all column but from the second table I want to fetch only one column with average value using avg function with related id
How can I achieve this using SQL query?
You question doesn't have much description about the tables, so i can consider as there are two table Table1 and Table 2
For SQL Server
Also I suggest you to use JOIN
SELECT Table1.Id, Name, AVG(Table2.Column) AS average
FROM Table1 t1 JOIN table2 t2
ON t1.primarykey = t2.foriegnKey
GROUP By t1.ID, name
ORDER BY average DESC
In the above query we are joining two tables and matching values using Primary-Key/Foreign-Key, and selecting ID, name from Table1 while taking Average of SomeColumn of Table2 as average
Let me know if this helps you, also if you could explain your question in a better way there would be chances of getting better answer always(as other users will know your issue more properly), thanks :)
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly