This question already has answers here:
Fast way to discover the row count of a table in PostgreSQL
(7 answers)
Closed 8 years ago.
What question should I send to database, to check how many rows my table contains?
SELECT COUNT(*) FROM table_name;
Related
This question already has answers here:
Fetch the rows which have the Max value for a column for each distinct value of another column
(35 answers)
GROUP BY with MAX(DATE) [duplicate]
(6 answers)
Oracle SQL query: Retrieve latest values per group based on time [duplicate]
(2 answers)
Select First Row of Every Group in sql [duplicate]
(2 answers)
How to return only latest record on join [duplicate]
(6 answers)
Closed 10 months ago.
I have done similar SQL queries in my opinion already before but this is somehow impossible although sounds easy... I hope you can help me in this, I have checked multiple answers for relating questions finding no working solution. I'm using SQL Developer.
I have two tables:
FAMILY
and FAMILY_PLAN
And I need to find only the newest FAMILY_PLAN to each person. And the answer should be like this:
Thank you for your help!
This question already has answers here:
SQL Server dynamic PIVOT query?
(9 answers)
SQL dynamic unpivot table as function
(1 answer)
Closed 2 years ago.
I have table:
I want use UNPIVOT to create table, where CategoryNames rows are columns names.
So, now I can just write this as
SELECT Year, Seafood, Meat/Poultry, [...]
FROM [...] UNPIVOT(...) AS Example
but I don't want write every row manually as column name, so is any option to use
SELECT CategoryName
FROM Pods
query result to create them automatically.
For this example its only 8 row, but with bigger count this could be very helpful.
This question already has answers here:
Delete duplicate records from a SQL table without a primary key
(20 answers)
Closed 2 years ago.
Table:
|date|ticker|eps|
|2020|AAPL|2.65|
|2019|AAPL|1.44|
|2019|GSKY|2.45|
|2020|GOOGL|0.45|
|2019|GOOGL|3.43|
Expected Output:
I want to delete a duplicate previous year ticker row but keep the recent year row (i.e 2020)
|date|ticker|eps|
|2020|AAPL|2.65|
|2019|GSKY|2.45|
|2020|GOOGL|0.45|
SELECT [ticker],MAX([date]) as [date]
INTO [NEW_TABLE]
FROM [TABLE]
GROUP BY [ticker]
This question already has answers here:
Query to list number of records in each table in a database
(23 answers)
Closed 7 years ago.
I am working with SQL Server 2008 R2.
I have a table named punch with lot of rows. I want to know number of rows in this table but without doing a count. Is it possible? If yes then how?
Thanks
Sql have a function for that
sp_spaceused <Tablename>;
Here is one way.
select row_count
from sys.dm_db_partition_stats
where object_id = object_id('punch')
This question already has answers here:
Randomly Select a Row with SQL in Access
(4 answers)
Closed 7 years ago.
I'm trying to make a Query from my Table "Questions", this table has the following fields: id(auto number), Question(text) ; Category(text), difficulty (number)
The query I'm trying to make must return one random row for every difficulty (1-5), for a given Category.
In SQL you can do something like this:
SELECT TOP 1 * FROM Questions ORDER BY NEWID()