473,385 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Groupped count(*) results from a view

All,

I have a view that returns the following values:

Item Vendor
70807 1234
70807 5678

If I am looking for items that have more than one vendor:
select item_num,count(*)
from myview
group by item_num
having count(*) > 1;

returns: no rows found.

If I use a table instead of the view everything works as expected.
Is there a way around this issue?
Oracle version 8.1.7 on Sun.

TIA

Michael

Jul 19 '05 #1
5 5946
Nic

"Michael Krzepkowski" <NO************@sqlcanada.com> wrote in message
news:3F**************@sqlcanada.com...
All,

I have a view that returns the following values:

Item Vendor
70807 1234
70807 5678

If I am looking for items that have more than one vendor:
select item_num,count(*)
from myview
group by item_num
having count(*) > 1;

returns: no rows found.

If I use a table instead of the view everything works as expected.
Is there a way around this issue?
Oracle version 8.1.7 on Sun.
What's the definition of the view "myview"?


TIA

Michael

Jul 19 '05 #2
Nic wrote:
"Michael Krzepkowski" <NO************@sqlcanada.com> wrote in message
news:3F**************@sqlcanada.com...

All,

I have a view that returns the following values:

Item Vendor
70807 1234
70807 5678

If I am looking for items that have more than one vendor:
select item_num,count(*)
from myview
group by item_num
having count(*) > 1;

returns: no rows found.

If I use a table instead of the view everything works as expected.
Is there a way around this issue?
Oracle version 8.1.7 on Sun.


What's the definition of the view "myview"?

TIA

Michael


Here it is:

select unique item_vend_item.item_num,
vend_item.vendor_num
from item_vend_item, vend_item
where item_vend_item.vend_item_id =
vend_item.vend_item_id
Michael

Jul 19 '05 #3
Nic
It because you use the UNIQUE keyword in the SELECT part of the view definition. Unique ensure that each rows return are unique...so there can't be any HAVING COUNT(*) > 1 for any grouping on the view.

You could figure it easy by yourself, you just have to query the base table, look at the result then query the view and try to find duplicate item_num...

"Michael Krzepkowski" <NO************@sqlcanada.com> wrote in message news:3F**************@sqlcanada.com...
Nic wrote:

"Michael Krzepkowski" <NO************@sqlcanada.com> wrote in message
news:3F**************@sqlcanada.com...
All,

I have a view that returns the following values:

Item Vendor
70807 1234
70807 5678

If I am looking for items that have more than one vendor:
select item_num,count(*)
from myview
group by item_num
having count(*) > 1;

returns: no rows found.

If I use a table instead of the view everything works as expected.
Is there a way around this issue?
Oracle version 8.1.7 on Sun.

What's the definition of the view "myview"?
TIA

Michael



Here it is:

select unique item_vend_item.item_num,
vend_item.vendor_num
from item_vend_item, vend_item
where item_vend_item.vend_item_id =
vend_item.vend_item_id
Michael

Jul 19 '05 #4
Nic wrote:
It because you use the UNIQUE keyword in the SELECT part of the view
definition. Unique ensure that each rows return are unique...so there
can't be any HAVING COUNT(*) > 1 for any grouping on the view.

You could figure it easy by yourself, you just have to query the base
table, look at the result then query the view and try to find
duplicate item_num...
Look at my example: I can have two different vendors for the same item.
The query is supposed to find
all items (and the count of vendors) only where there is more than one
occurence i.e.
if an item has only one vendor, I don't want to see it.

I have exactly the same dataset in Informix and results are correct.
Is my syntax incorrect for Oracle?

Michael


"Michael Krzepkowski" <NO************@sqlcanada.com
<mailto:NO************@sqlcanada.com>> wrote in message
news:3F**************@sqlcanada.com...
Nic wrote:
"Michael Krzepkowski" <NO************@sqlcanada.com> wrote in message
news:3F**************@sqlcanada.com...

All,

I have a view that returns the following values:

Item Vendor
70807 1234
70807 5678

If I am looking for items that have more than one vendor:
select item_num,count(*)
from myview
group by item_num
having count(*) > 1;

returns: no rows found.

If I use a table instead of the view everything works as expected.
Is there a way around this issue?
Oracle version 8.1.7 on Sun.


What's the definition of the view "myview"?

TIA

Michael


Here it is:

select unique item_vend_item.item_num,
vend_item.vendor_num
from item_vend_item, vend_item
where item_vend_item.vend_item_id =
vend_item.vend_item_id
Michael

Jul 19 '05 #5
Nic

"Michael Krzepkowski" <NO************@sqlcanada.com> wrote in message news:3F**************@sqlcanada.com...
Nic wrote:

It because you use the UNIQUE keyword in the SELECT part of the view definition. Unique ensure that each rows return are unique...so there can't be any HAVING COUNT(*) > 1 for any grouping on the view.

You could figure it easy by yourself, you just have to query the base table, look at the result then query the view and try to find duplicate item_num...
Look at my example: I can have two different vendors for the same item. The query is supposed to find
all items (and the count of vendors) only where there is more than one occurence i.e.
if an item has only one vendor, I don't want to see it.

I have exactly the same dataset in Informix and results are correct.
Is my syntax incorrect for Oracle?

Yes your syntax is correct!!

But I'm a little confused about of what and how your doing... I mean you said your query work great with the base table and not with the view, so it's obvious the syntax is ok. Also if you want to check a query, for syntax and logic, you simply need to log in SQL*Plus and give it a try, Oracle will give you pretty good feed back about the syntax and you can check the logic with the results...

I work a lot with Oracle 8i on solaris and I never heard a of kind a bug related to your problem, sorry but I truly belive that there ain't no duplicate "item_num" in your view...

Good luck.
Michael
"Michael Krzepkowski" <NO************@sqlcanada.com> wrote in message news:3F**************@sqlcanada.com...
Nic wrote:

"Michael Krzepkowski" <NO************@sqlcanada.com> wrote in message
news:3F**************@sqlcanada.com...
All,

I have a view that returns the following values:

Item Vendor
70807 1234
70807 5678

If I am looking for items that have more than one vendor:
select item_num,count(*)
from myview
group by item_num
having count(*) > 1;

returns: no rows found.

If I use a table instead of the view everything works as expected.
Is there a way around this issue?
Oracle version 8.1.7 on Sun.

What's the definition of the view "myview"?
TIA

Michael



Here it is:

select unique item_vend_item.item_num,
vend_item.vendor_num
from item_vend_item, vend_item
where item_vend_item.vend_item_id =
vend_item.vend_item_id
Michael

Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andy | last post by:
I need to be able to count the number people who are registered in a certain IT course. i need to display the results on a form or report. This is for my A level courswork please help! thanks
10
by: Zak McGregor | last post by:
Hi all is it possible to get a count(1) statemment, for example here: select count(1) from results where fixture=4916 and winner=away group by winner; to return a 0 value instead of...
3
by: Michel de Becdelièvre | last post by:
I need your help here : I need to compute the product of a column, with conditions, over a table, grouped by a key (it is a probability table). In fact I need the exact equivalent of : ...
4
by: Chris | last post by:
Can't seem to figure out how to do this and have been reading for some time now...... I want to select a row count from a table name in SYSTABLES. This statement does not return what I needed,...
2
by: jonathan184 | last post by:
Hi I am having a problme where the results of the sql count is not matching the results of the perl script sql count. The script was working fine up till Wed last week and after that the results...
3
by: ret4rt | last post by:
Hello. I have a database with movies similar with imdb and i want to find out which directors have directed both thriller and drama movies. The output i want is like this "DIR_NAME,amount of...
8
by: C10B | last post by:
hi, I have a table with several million rows. Each row is simply the date and time a certain page was viewed. eg page1 1-1-00 page2 2-1-00 page1 16-1-00 page1 17-1-00
5
by: Michael Krzepkowski | last post by:
All, I have a view that returns the following values: Item Vendor 70807 1234 70807 5678 If I am looking for items that have more...
3
by: M. Mehta | last post by:
It seems that you can not create a materialized view if you are using outer joins...can someone please verify this? Thanks M. Mehta Please follow my example below: created 2 tables:
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.