Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: Using count(*) in where question

Started 1 month, 3 weeks ago by antigenius
Hello everyone, I am new in here, had already search the rest of the forum and find out here is probably the biggest. I read all my books but still having problem for the display my sub query commands. I try to display the name of the major that has the largest number of students. and here are things what I came out so far. at the first time I try to do this, but of course it ...
Site: dBforums - Database Support Community  dBforums - Database Support Community - site profile
Forum: ANSI SQL  ANSI SQL - forum profile
Total authors: 24 authors
Total thread posts: 6 posts
Thread activity: 26 new posts during last week
Domain info for: dbforums.com

Other posts in this thread:

vickrampurswani replied 3 months ago
Hi All, this is my first post on any forum. It would be great if someone can tell me whether to use OR or a UNION when both are giving same results. Also i want to know is the use of CASE statement like below correct ? here are two queries that I am talking about 1 ++++++++++++++++++++++++++++++++++++++++++++++++ + SELECT 'FAILED' ...

mike_bike_kite replied 3 months ago
Just some quick comments: Welcome to the forum! What RDBMS are you using? If both statements produce the correct answer in a reasonable time then both statements are correct. Personally I find the OR easier to read. You are missing a select after the union keyword. You should use a.eventstatuscode = 'abc' rather than a.eventstatuscode IN ('abc') Your first case statement uses = while the ...

pootle flump replied 3 months ago
Mike - I _think_ these are non ANSI outer joins. As such, I would recommend changing the joins to ANSI. I'm fairly sure there are more syntax errors in those queries too.... OP - are you sure these run?

r937 replied 3 months ago
no, these aren't wacky outer joins, the operator is "=" in all cases the queries are using a single run-time parameter, :srcaccountid

pootle flump replied 3 months ago
Ah ok. Note this wasn't in ANSI SQL when first posted otherwise I wouldn't have responded and displayed my ignorance. I'd still use ANSI joins though, be they innies or outies.

vickrampurswani replied 3 months ago
Quote: Originally Posted by pootle flump Mike - I _think_ these are non ANSI outer joins. As such, I would recommend changing the joins to ANSI. I'm fairly sure there are more syntax errors in those queries too.... OP - are you sure these run? I missed 1 select after UNION while pasting it. the query works flawlessly ,...

vickrampurswani replied 3 months ago
Quote: Originally Posted by mike_bike_kite Just some quick comments: Welcome to the forum! What RDBMS are you using? If both statements produce the correct answer in a reasonable time then both statements are correct. Personally I find the OR easier to read. You are missing a select after the union keyword. You should use a.eventstatuscode = 'abc' ...

r937 replied 3 months ago
Quote: Originally Posted by pootle flump Note this wasn't in ANSI SQL when first posted... it wasn't in the oracle forum, by any chance, was it?

pootle flump replied 3 months ago
No - dbconcepts

Rachel_B replied 2 months, 4 weeks ago
Perhaps this is a daft question as I am new to SQL. Assume I have a table like this ... company city Microsoft New York IBM Chicago Red Hat Detroit Red Hat New York Red Hat San Francisco NVIDIA New York NVIDIA LA NVIDIA LA What I want as an output is .... company LA Detroit Chicago NVIDIA 2 0 0 Red Hat 0 1 0 .... etc Maybe I'm trying to do something ...

 

Top contributing authors

Name
Posts
r937
20
user's latest post:
Help with sorting results
Published (2009-12-10 16:23:00)
Code: SELECT t.title , p.last_post FROM Topic AS t INNER JOIN ( SELECT idtopic , MAX(dateadded) AS last_post FROM Post GROUP BY idtopic ) AS p ON p.idtopic = t.idtopic WHERE t.idforum =1 ORDER BY p.last_post DESC
BettingSherlock
12
user's latest post:
how do i insert a null value...
Published (2009-10-29 13:15:00)
btw, someone please shoot me in the other foot
shammat
11
user's latest post:
Strange results when working out...
Published (2009-12-11 04:34:00)
Quote: Originally Posted by JarlH You originally claimed I said that you can have a column in the GROUP BY that is not in the SELECT list. Here you are trying to do the opposite, a column id in the SELECT list which " is not contained in either an aggregate function or the GROUP BY clause ". Sorry for that, that was indeed incorrectly put on my side. My example statement is valid for MySQL and that's what I wanted to...
olel
9
user's latest post:
Help with a very slow SQL-Statement
Published (2009-12-04 07:40:00)
Maybe we will have to run the SQL directly indeed. But then we do have the problem that the SQL isn't working with MySql and we have to make sure that we are independend of the dbms used. So if we decide to run it directly we need another SQL nevertheless - one for all dbms. Some help? ;-)
JarlH
8
user's latest post:
Strange results when working out...
Published (2009-12-11 04:48:00)
Quote: Originally Posted by shammat Sorry for that, that was indeed incorrectly put on my side. My example statement is valid for MySQL and that's what I wanted to point out (the shortcomings of grouping in MySQL) Re-reading my posts from a "distance" I do understand the confusion. Sorry again, next time I'll try to be more precise... Never mind. Have a nice weekend!
stolze
7
user's latest post:
If else?
Published (2009-12-11 12:22:00)
You can also use "COALESCE(NULLIF(actual, 0), estimated)".
antigenius
4
user's latest post:
Using count(*) in where question
Published (2009-10-22 12:05:00)
Quote: Originally Posted by Pat Phelan What if there are ties (such as seventy-two majors that only have one student)? What if the majors with the fewest advisors are not the majors with the most students? -PatP Thank you PatP. and yes that's the problem that I am facing now. the majors i got form the database is not the most student. sign~ I sent a email to my TA and my teacher already last night already but haven't get any reply...
khdani
4
user's latest post:
difference of two queries
Published (2009-11-14 10:44:00)
i think i got it, thank you for explaining
gvee
4
user's latest post:
Multi-Row-Update
Published (2009-12-01 11:42:00)
What DBMS are you using? ANSI update behaviour/syntaxt differs from, say, Microsoft SQL Server, so yo may get a more appropriate answer if you supply us with this information
Nebraska_God
4
user's latest post:
If else?
Published (2009-12-11 05:09:00)
I got it. I used a case statement.

Related threads on "dBforums - Database Support Community":

Related threads on other sites:

Thread profile page for "Using count(*) in where question" on http://www.dbforums.com. This report page is a snippet summary view from a single thread "Using count(*) in where question", located on the Message Board at http://www.dbforums.com. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity