Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Refer to the given SQL statement.
1. Select SPNAME
2. FROM SALESPERSON
3. Where SPNUM=
4. FROM CUSTOMER
5. WHERE CUSTNUM=20900);
What is missing from the subquery at the beginning of line 4?
(SELECT SPNUM
(SPNUM
(Subquery SPNUM
(FIND SPNUM
I think the query should be WHERE SPNUM = ... or WHERE SPNUM IN ... followed by a subquery. To be safe, we can use WHERE SPNUM IN ... in the event that the subquery return more than one record.
SELECT SPNAME
FROM SALESPERSON
WHERE SPNUM IN (SELECT SPNUM FROM CUSTOMER WHERE CUSTNUM = 20900)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
I have this SQL statement:
select
v.venue_id, v.name
from
venues v
where
not exists (select e.vid
from events e
where e.vid = v.venue_id);
Here is the result of the query:
It works fine but the last row in the result is null, how do I remove that? Been trying for a bit now with no luck
I think this might be what you're experiencing
Why does SQL workbench always return a row full of null values in every query?
Looks like that's normal behavior
The null row is per design, disregard it. i thought you were firstly referring to a column.
on your where statement <field> is not null
So:
select v.venue_id, v.name
from venues v
where not exists (
select e.vid
from events e
where e.vid = v.venue_id
and name is not null
);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
How can I write this query without TOP and Limit only use the SQL
You just sort the data one way, grab the records you want, then sort it the other way:
SELECT SOME_FIELD
FROM (SELECT st.*
FROM SOME_TABLE st
ORDER BY SOME_FIELD DESC)
WHERE ROWNUM <= 7
ORDER BY SOME_FIELD ASC
dbfiddle here
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a table name customers with two columns, case id and owner. I need to write a query to select random 5 caseids for every name in owner column.please help
For a start, you need something like:
SELECT TOP 5
ID,
[Case ID],
[Owner],
Rnd(-Timer()*[ID]) AS RandomRecord
FROM
[Cases]
ORDER BY
Rnd(-Timer()*[ID]);
to be used as a subquery filtered on OwnerID of your Owners' table.
I once posted an article on this with a lot more details:
Random Rows in Microsoft Access
You can use in:
select t.*
from t
where t.id in (select top 5 id
from t as t2
where t2.name = t.name
order by Rnd(-Timer()*[ID])
);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have a id which is having more than one Accountid in a table with status Active . I need to find group of active for the particular ID .
Please find my below query .is it correct or something need to modify to get better optimized result .
select id,count(Accountid) from CustomerAccount
where status='Active'
group by id
having count(*)>( select min(maxxount) from(
select id,count(accountid) as maxxount
from CustomerAccount
group by id)A)
Use this query:
select id,count(Accountid) from CustomerAccount
where status='Active'
group by id
having count(*) >1
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Union all function is not working inside the Recursive CTE...?
with CTE_Manager(id,manager,man_id,[Level])
as
(
select id,manager,man_id,1
from manager
where man_id is null
union all
select a.id,a.manager,a.man_id,b.[Level]+1
from manager a
join CTE_Manager b
on b.man_id= a.id
)
select a.manager,ISNULL(a.manager,'SUPER BOSS'),b.Level
from CTE_Manager a
join CTE_Manager b
on a.man_id=b.id
Actually i am getting the output:
I am retrieving the value before the union all function.I have to get all the values from the recursive CTE.
The on clause in your join is the wrong way around. It should be b.id = a.man_id.
What you have done is selected all managers that don't have a manager and then tried to find their manager. When what I suspect you want is all of their subordinates.