?
Solved

A SQL that must be supported by the Access, MySQL, Microsoft SQL servers

Posted on 2003-03-04
40
Medium Priority
?
199 Views
Last Modified: 2011-10-03
A SQL that must be supported by the Access, MySQL, Microsoft SQL servers. The table is like this:

name1 name2 date     cant
a1    b1    2-3-2003  12
a1    b1    1-3-2003  11
a1    b2    3-3-2003  13
a1    b2    2-3-2003  14
a2    b3    2-3-2003  12
a2    b3    1-3-2003  11

I want to obtain the result:

name1 name2 date     cant
a1    b1    2-3-2003  12
a1    b2    3-3-2003  13
a2    b3    2-3-2003  12

0
Comment
Question by:leonteanupotelin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 30
  • 6
  • 2
  • +2
40 Comments
 

Author Comment

by:leonteanupotelin
ID: 8064551
answer
0
 

Author Comment

by:leonteanupotelin
ID: 8064599
answer
0
 
LVL 1

Expert Comment

by:BWarmuskerken
ID: 8064601
Select name1, name2, date, cant from YourTable where date >= #2/3/2003#
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:Glowman
ID: 8064603
SELECT * FROM Table1 Where
cant=12 or cant=13;

or is there some other way you want to come up with your return set?
0
 
LVL 1

Expert Comment

by:lucho_nd
ID: 8064648
Hi!:
I assume the table's name is Table1

select name1, name2, max(date), cant from table1
group by name2 order by name2

good luck

lucho_nd
0
 

Author Comment

by:leonteanupotelin
ID: 8064705
answer
0
 
LVL 1

Expert Comment

by:BWarmuskerken
ID: 8064729
I'm sure we could all come up with a bunch of different ways to return the same sub set.  We need more detail as what you are basing the selection on.   Is it the date? The cant?  Is it where name1 = a1 and the date is greater than 2/1/03? etc...
0
 

Author Comment

by:leonteanupotelin
ID: 8064777
Just lucho_nd understand my question, but this variant don't work in access. I want a Sql query that must work with any of the above DBMS.
0
 

Author Comment

by:leonteanupotelin
ID: 8064797
select name1, name2, max(date), cant from table1
group by name2 order by name2

This query work, but just in SQL and MySQL DBMS. I want a query that work with any of DBMS (SQL, MySQL, Access)...
0
 

Author Comment

by:leonteanupotelin
ID: 8064836
answer
0
 

Author Comment

by:leonteanupotelin
ID: 8064871
answer
0
 

Author Comment

by:leonteanupotelin
ID: 8064900
select name1, name2, max(date), cant from table1
group by name2 order by name2

With this SQL Query I obtain the error:

"error '80040e14' [Microsoft][ODBC Microsoft Access Driver] You tried to execute a
query that does not include the specified expression 'articlenumber' as part ... "
0
 

Author Comment

by:leonteanupotelin
ID: 8064911

error '80040e14' [Microsoft][ODBC Microsoft Access Driver] You tried to execute a
query that does not include the specified expression 'articlenumber' as part of an aggregate function ...
0
 

Author Comment

by:leonteanupotelin
ID: 8064931
answer
0
 

Author Comment

by:leonteanupotelin
ID: 8064959
answer
0
 

Author Comment

by:leonteanupotelin
ID: 8064966
answer lucho_nd
0
 

Author Comment

by:leonteanupotelin
ID: 8064981
answer all
0
 

Author Comment

by:leonteanupotelin
ID: 8065071
answer all
0
 

Author Comment

by:leonteanupotelin
ID: 8065082
answer all
0
 

Author Comment

by:leonteanupotelin
ID: 8065131
answer all
0
 

Author Comment

by:leonteanupotelin
ID: 8065221
answer all
0
 

Author Comment

by:leonteanupotelin
ID: 8065570
answer all
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8065672
just out of curiosity, where does the field "articlenumber" come from.  I do NOT see that field name in the query:

select name1, name2, max(date), cant from table1
group by name2 order by name2

That you SAID you used, when you got the error.

If that was NOT the REAL SQL that you used, then PLEASE show us the REAL SQL that you DID use.

AW
0
 

Author Comment

by:leonteanupotelin
ID: 8065689
answer all
0
 
LVL 1

Expert Comment

by:lucho_nd
ID: 8065737
Hi!:

The error refer to a field called 'articlenumber', what field is that????

The SQL query I send is correct. You should try it in Query Wizard from Access. And try change the name Date (for ex Date1) also.

Good luck

lucho_nd
0
 

Author Comment

by:leonteanupotelin
ID: 8065752
Ok, then the error is:
error '80040e14' [Microsoft][ODBC Microsoft Access Driver] You tried to execute a
query that does not include the specified expression 'name1' as part of an aggregate function ...

This was just an exemple like my case and the error was from another place. The error above is the true error...
0
 

Author Comment

by:leonteanupotelin
ID: 8065772
lucho_nd, try the query from visual basic and you will see the error above...
0
 

Author Comment

by:leonteanupotelin
ID: 8065801
answer
0
 
LVL 1

Expert Comment

by:lucho_nd
ID: 8067723
Try this, but I don´t know if this query run in all the Servers.

select name1, grouptable.name2, maxdate, cant
from table1, (select name2, max(date) as maxdate
              from table1
              group by name2) grouptable
where table1.name2 = grouptable.name2
     and table1.date = grouptable.maxdate
order by grouptable.name2


The other option is use two select sentences

select name2, max(date) as maxdate
from table1
group by name2 into grouptable

select name1, grouptable.name2, maxdate, cant
from table1, grouptable
where table1.name2 = grouptable.name2
     and table1.date = grouptable.maxdate
order by grouptable.name2


good luck

lucho_nd
0
 

Author Comment

by:leonteanupotelin
ID: 8070406
hello lucho_nd

Your answer is interesting but I want to test it with all DBMS and I will be back...
thank you
0
 

Author Comment

by:leonteanupotelin
ID: 8070471
I don't create a new table like 'grouptable'.
0
 

Author Comment

by:leonteanupotelin
ID: 8070474
I don't want to create a new table like 'grouptable'.
0
 

Author Comment

by:leonteanupotelin
ID: 8070538
I don't want to create a new table like 'grouptable'.
0
 
LVL 1

Expert Comment

by:lucho_nd
ID: 8071873
Hi!!

The first option would be the only one. It execute correctly in SQL Server.

good luck
lucho_nd

select name1, grouptable.name2, maxdate, cant
from table1, (select name2, max(date) as maxdate
             from table1
             group by name2) grouptable
where table1.name2 = grouptable.name2
    and table1.date = grouptable.maxdate
order by grouptable.name2


0
 

Author Comment

by:leonteanupotelin
ID: 8071923
Thank you verry mutch, but this query don't work in MySql server :)...nested queries!!!
0
 
LVL 1

Expert Comment

by:lucho_nd
ID: 8074258
Hi!!
there are no other choice, take it or leave it :-D

good luck

lucho_nd

0
 

Author Comment

by:leonteanupotelin
ID: 8078575
Ok, you are the winner but my problem is until unresolved:(
nashpa
0
 
LVL 1

Accepted Solution

by:
lucho_nd earned 150 total points
ID: 8080932
Hi!!

Why don't you make three versions of the query and execute it depending of the current server.

good luck

lucho_nd
0
 

Author Comment

by:leonteanupotelin
ID: 8081007
I want to make a portable program. The problem is with the Access because I don't make a query. I resolv the problem but dinamicaly by manipulate the recordset.  
0
 

Author Comment

by:leonteanupotelin
ID: 8081020
Thank you
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question