How to remove null from results [closed] - sql

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
);

Related

Merge row values from the same value key in SQL [closed]

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 2 years ago.
Improve this question
Permission to ask, why is this the error? I try
select user_idea.idea_id,user_idea.title, idea_events.events, idea_categories.category_name AS category
from user_idea
LEFT join idea_events
on user_idea.idea_id=idea_events.idea_id
LEFT JOIN idea_categories
ON user_idea.idea_categories=idea_categories.category_id;
The result is sqliteonline like this:
I want to combine Dewasa and Anak events because of the same idea. For category why is the result NULL for values 1;2 not read in the idea_category table which should be Mudah; Sedang.
For table:
Output expected:
select user_idea.idea_id,user_idea.title,
(SELECT GROUP_CONCAT(events,';') FROM idea_events Where user_idea.idea_id=idea_events.idea_id) as events,
(SELECT GROUP_CONCAT(category_name ,';') FROM idea_categories Where user_idea.idea_categories=idea_categories.category_id) AS category
from user_idea;
1:2 idea_categories in user_idea is not considered as relevant to join so when joined it cannot find the data in other table here so data is null
reminder
before doing join just analyse the data anomalies like not having common data and properly formatted

SQL returns null data [closed]

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 2 years ago.
Improve this question
I need to remove values ​​that has null result (second row)
Your query that you posted uses correlated sub queries to get the results that could easily achieved with a left join. Changing that left join into an inner join will get rid of the nulls as long as you do not have nulls in the name column of the emp table.
select e.empno,e.ename,mngr.name
from emp e
inner join emp mngr on e.mgr=mngr.empno

sql in ms-access [closed]

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])
);

SQL Server Temp Table to a Select Distinct Count Distinct quetsion [closed]

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
Ok, basically I've got a lot of temp tables I've created and I'm trying to create Validation for the ProvDiff table.
DROP TABLE #ProvDiff;
IF OBJECT_ID ('temp.dbo.#ProvDiff') IS NOT NULL
DROP TABLE #ProvDiff;
SELECT *
INTO #ProvDiff
FROM
(SELECT DISTINCT *
FROM #finalclaimswithflags f
WHERE f.[Pay-To Prov NPI] <> f.[Rendering Prov NPI]) ProvDiff;
SELECT DISTINCT COUNT(DISTINCT ???) AS 'Unique EI NPIS'
FROM #ProvDiff
In my head it seems like the differences should be able to produce a result and I should be able to do a count on that. But for the life of me I can't figure out how to do that. If I do a count on rendering or pay to then those numbers wouldn't necessarily reflect the value for what are above. I know how many of each are produced for above validation.
Any help would be greatly appreciated
Is this what you want?
SELECT COUNT(*)
FROM (SELECT DISTINCT *
FROM #finalclaimswithflags f
WHERE f.[Pay-To Prov NPI] <> f.[Rendering Prov NPI]
) ProvDiff;
I don't see why a temporary table would be used for this.
For better or worse, SQL Server does not support select count(distinct *), so you pretty much need a subquery.

Recursive CTE in SQL [closed]

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.