SELECT COUNT(*) from customer_tbl is giving 8000 as count.
If I do SELECT * from customer_tbl is returning only 2 records.
I have gathered the stats on the table still same problem.
Could you please help me.
Thanks in advance.
Related
This works to select top 100 columns, but it gives me all of the columns
select top 100 * from dw.test
This works, but it gives me endless rows,
select Slot, ID from dw.test
I need to select top 100 rows that only show these two columns Slot, ID
I cannot get it to work no matter how I try to combine them,
Please help create this query. Thank you
try it
select TOP(100) Slot, ID from dw.test ORDER BY Slot, ID DESC
It's not clear to me which RDBMS is being used, but one of the following should work:
SELECT TOP(100) Slot, ID FROM dw.test;
Limit instead?
SELECT Slot, ID FROM dw.test LIMIT 100;
What is the difference between the below codes.
Select count(distinct(*)) from TableName;
Select count(*) from (Select distinct(*) from TableName;
I am running this code on azure Databricks and getting different values after executing both the codes. I am not sure why is this happening. Any help would be highly appreciated.
I have a query I can not seem to get to work.
I have a table like this:
ThingID, FK_ThingTypeID, Etc...
And I want to select records in the order they were inserted, but group them by type. So if the data looks in the table is in the following order:
ThingID, FK_ThingTypeID
1 1
2 2
3 1
4 1
I want to get select the records like this:
ThingID, FK_ThingTypeID
1 1
3 1
4 1
2 2
So they are in the order they were added, but grouped by type.
I have tried using ORDER BY and GROUP BY for this but no combination of what I try works, and all the GROUP BY examples I see are working with aggregate functions. I am not interested in counts or max etc.. I just want to order the records as above. I have tried just using an ORDER BY ThingID, FK_ThingTypeID, but this just lists them by ID and does not group by the types. There are a stack more columns in the table and using GROUP BY requires that I add all these, and then it doesn't work anyway.
Can anyone give an example of an approach to achieve the result I am looking for?
Thanks for your time.
Thanks for those that responded.
Here was the solution:
SELECT
t.*
FROM
Thing t
ORDER BY
(
SELECT
min(ref.ThingID)
FROM Thing ref
WHERE
ref.ThingTypeID = t.ThingTypeID
),
t.ThingID
May be this query is helpful for you as per my understanding:
select * from table order by rownum, FK_ThingTypeID
You can try below query:
select ROW_NUMBER() OVER(
ORDER BY THINGID) AS RowNum, FK_ThingTypeID from table
Your query seems simple so am sure someone will be able to help.
Gotta love Stack Overflow.
I had a go not sure whether this is what you are after?
Apologies if not
SELECT ThingID,FK_ThingTypeID
FROM Table
ORDER BY FK_ThingTypeID, ThingID
I hope I can explain this properly.
This is what the result of the table looks like
Content_IDs of 4,5,6 are NEWS. As long as there is one boolean of true the column IsContentUpdated for NEWS, I'd like the distinct NEWS boolean to be true otherwise false.
Ultimately what I'd just want to get is
I tried with a temp table with a count of IsContentUpdated but it didn't work very well.
I'm kind of convinced I shouldn't need a temp table but am having a brain cramp trying to think what I can do here.
Any help is greatly appreciated. Thanks!
not sure I understand well, but if what you wanna get is what you show, it should be
SELECT Page_ID, MAX(CAST(IsContentUpdated AS INT))
FROM Table
GROUP BY Page_ID
This will give you a distinct list of the Page_IDs and whether or not any of them have a IsContentUpdated = 1:
select distinct Page_ID, max(IsContentUpdated)
from myTable
group by Page_ID
I need to know how many records were returned in a select in oracle. Currently, I do two queries:
SELECT COUNT(ITEM_ID) FROM MY_ITEMS;
SELECT * FROM MY_ITEMS;
I need to know the COUNT but I hate doing two queries. Is there a way to do:
SELECT * FROM MY_ITEMS
and then find out how many records are in there?
Is there a way to do:
SELECT * FROM MY_ITEMS
and then find out how many records are in there?
If you want it to be in this exact order, you can fetch all records on the client and count their number (almost all client libraries provide a function for that).
You can also do:
SELECT i.*, COUNT(*) OVER ()
FROM my_items i
, which will return you the count along with each record.
If you're working in PL/SQL, you can use the SQL%ROWCOUNT pseudo-variable to get the number of rows affected by the last SQL statement. Might save you some effort.
This ought to do the trick.
WITH
base AS
(
SELECT *
FROM MY_ITEMS
)
SELECT (SELECT COUNT(*) FROM base) kount,
base.*
FROM base
I'm just unsure about the table aliases, I don't remember in Oracle if they require 'AS' or not. But this should work.
select mt.*, c.Cntr
from MyTable mt
, (select COUNT(*) as Cntr
from MyTable
) c