SQL Query

SQL Query

Post by Anan » Sun, 03 Aug 2003 07:51:13



Hi all

I need to write an SQL like

Select distinct column1 from table1
where column1='Test'
Group by Column1
Order by Column2

B'coz ORDER BY items must appear in the select list if
SELECT DISTINCT is specified.

Is it possible using sub query we can sole this. I don't
want to use a temp table.

Thanks in advance
Anand

 
 
 

SQL Query

Post by Ray a » Sun, 03 Aug 2003 08:04:02


Okay, I am in no way a querying expert or even a novice, but "select
distinct column1 where column1='something'" will always return just one
single record, yes?  So, why would ordering even matter, unless you're
trying to get just one column with a lowest column2 value.  If that's the
case, I'd do:

select top 1 column1 where column1='Test' order by column2

Ray at home

--
Will trade ASP help for SQL Server help


Quote:> Hi all

> I need to write an SQL like

> Select distinct column1 from table1
> where column1='Test'
> Group by Column1
> Order by Column2

> B'coz ORDER BY items must appear in the select list if
> SELECT DISTINCT is specified.

> Is it possible using sub query we can sole this. I don't
> want to use a temp table.

> Thanks in advance
> Anand


 
 
 

SQL Query

Post by Vlad Vissoultche » Sun, 03 Aug 2003 15:36:38


then i wonder what does a DISTINCT do with a GROUP BY clause!?

re the original question:

select country
from customers
group by country
order by max(companyname)

works just fine in Northind db.

cheers,
</wqw>



> Okay, I am in no way a querying expert or even a novice, but "select
> distinct column1 where column1='something'" will always return just one
> single record, yes?  So, why would ordering even matter, unless you're
> trying to get just one column with a lowest column2 value.  If that's the
> case, I'd do:

> select top 1 column1 where column1='Test' order by column2

> Ray at home

> --
> Will trade ASP help for SQL Server help



> > Hi all

> > I need to write an SQL like

> > Select distinct column1 from table1
> > where column1='Test'
> > Group by Column1
> > Order by Column2

> > B'coz ORDER BY items must appear in the select list if
> > SELECT DISTINCT is specified.

> > Is it possible using sub query we can sole this. I don't
> > want to use a temp table.

> > Thanks in advance
> > Anand

 
 
 

SQL Query

Post by Bob Barrow » Sun, 03 Aug 2003 15:44:05


You're missing the "Where country='something'" line, which was what Ray was
commenting on. Put that line into the query, and then tell us what the use
of either the "group by" or "order by" clauses is.

Bob Barrows


> then i wonder what does a DISTINCT do with a GROUP BY clause!?

> re the original question:

> select country
> from customers
> group by country
> order by max(companyname)

> works just fine in Northind db.

> cheers,
> </wqw>

> "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in

>> Okay, I am in no way a querying expert or even a novice, but "select
>> distinct column1 where column1='something'" will always return just
>> one single record, yes?  So, why would ordering even matter, unless
>> you're trying to get just one column with a lowest column2 value.
>> If that's the case, I'd do:

>> select top 1 column1 where column1='Test' order by column2

>> Ray at home

>> --
>> Will trade ASP help for SQL Server help



>>> Hi all

>>> I need to write an SQL like

>>> Select distinct column1 from table1
>>> where column1='Test'
>>> Group by Column1
>>> Order by Column2

>>> B'coz ORDER BY items must appear in the select list if
>>> SELECT DISTINCT is specified.

>>> Is it possible using sub query we can sole this. I don't
>>> want to use a temp table.

>>> Thanks in advance
>>> Anand

 
 
 

SQL Query

Post by Vlad Vissoultche » Sun, 03 Aug 2003 15:57:33


i'm not "missing" it -- just "adding" more food for thought :-)) something's
fundamentally wrong with the query/question.

cheers,
</wqw>


> You're missing the "Where country='something'" line, which was what Ray
was
> commenting on. Put that line into the query, and then tell us what the use
> of either the "group by" or "order by" clauses is.

> Bob Barrows


> > then i wonder what does a DISTINCT do with a GROUP BY clause!?

> > re the original question:

> > select country
> > from customers
> > group by country
> > order by max(companyname)

> > works just fine in Northind db.

> > cheers,
> > </wqw>

> > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in

> >> Okay, I am in no way a querying expert or even a novice, but "select
> >> distinct column1 where column1='something'" will always return just
> >> one single record, yes?  So, why would ordering even matter, unless
> >> you're trying to get just one column with a lowest column2 value.
> >> If that's the case, I'd do:

> >> select top 1 column1 where column1='Test' order by column2

> >> Ray at home

> >> --
> >> Will trade ASP help for SQL Server help



> >>> Hi all

> >>> I need to write an SQL like

> >>> Select distinct column1 from table1
> >>> where column1='Test'
> >>> Group by Column1
> >>> Order by Column2

> >>> B'coz ORDER BY items must appear in the select list if
> >>> SELECT DISTINCT is specified.

> >>> Is it possible using sub query we can sole this. I don't
> >>> want to use a temp table.

> >>> Thanks in advance
> >>> Anand

 
 
 

1. Getting SQL queries to the Emulator SQL Query

I have a database loaded on the Emulator and would like to run queries
that I have in my WinXP environment on SQLCE Query.  I tried several
options with various problems -

1.  I tried to copy the query from WinXP Query Analyzer to the
Emulator SQLCE Query.  Nothing pastes when I try this.  So, I assume
that you can't transfer text from the WinXP clipboard to the Emulator
SQL CE Query clipboard.  Is this correct?

2.  I made a sql.txt file that I added to my .NET project.  This
project and my sql.txt file gets deployed to "\program
files\xyz\sql.txt" on the emulator.  So, now I have sql.txt on the
emulator.  But, with the emulator's SQL Query, I can only open folders
under the "My Documents" folder.  In otherwords, I can't get to
"\program files\xyz\sql.txt" folder/file.

I must be overlooking something obvious...

Thanks...

2. Retrieving # of records lost

3. UK query - Delphi3 - NT4-Memory leak on SQL Query to SQL/server 6.5

4. Using sp_sproc_columns to populate ADO in Visual Basic 6

5. Query fails on VB6 but runs on VB5 and SQL Query Tool

6. Oracle Services Opportunities

7. Local sql, query on query problem

8. jdbc driver classpath issue when java(j++) object called from vbscript in asp file

9. Query works in SQL Query Analyzer but doesn't work in DTS

10. SQL Query equivalent for MS Access Query

11. Running SQL Query outside Query Analyzer

12. Prediction query in SQL query analyzer

13. Need help Access queries ===> SQL queries