Solved

FIRST Statement in MySQL

Posted on 2008-09-30
8
341 Views
Last Modified: 2012-05-05
Dear Sir,

I have a big problem, I am using MySQL and i have about 500 or more data.
All I want is to take the first and the last Receipt number from the database based on the date entered.
Example, if there are 200 records i want OR001 and OR200 information to be displayed.
Please help on the matter, really lost.
Thanks a million

Regards
Muraly
0
Comment
Question by:Muraly
  • 3
  • 3
  • 2
8 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22604121
this should do:
SELECT * FROM yourtable ORDER BY date_entered ASC LIMIT 1
UNION ALL
SELECT * FROM yourtable ORDER BY date_entered DESC LIMIT 1

Open in new window

0
 
LVL 17

Accepted Solution

by:
leannonn earned 50 total points
ID: 22604130
Maybe something like this:
---
SELECT MIN(your_receipt_no_col), MAX(your_receipt_no_col) WHERE your_date_col = "2008-09-30";
---

If not, we'd appreciate more details...
0
 

Author Comment

by:Muraly
ID: 22604183
Dear Sir,

Both cannot work giving error messages, basically i am using MySQL, for PHP.
More information can be said that u have 5 records of data in a table and u want only the first and the last invoice number, not in between. How do i do that, is the syntax the same as the SQL
Please advice and thanks

Regards
Muraly
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22604193
>Both cannot work giving error messages
which error messages?

can you show how you used it, in php?
0
 
LVL 17

Expert Comment

by:leannonn
ID: 22604200
Both should work. Can you post your existing PHP code?
0
 
LVL 17

Expert Comment

by:leannonn
ID: 22604203
I'm constantly late... :( Sorry angelIII...
0
 

Author Comment

by:Muraly
ID: 22620641
Dear Sir,

Sorry for the late reply, my computer and internet provider was down
Below is the error message i got when i run in the MySQL 5.0.
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `INV_DATE` = '2008-09-30'' at line 1
Below is the SQL statement i use, i have changed the based on my table
SELECT MIN(`INV_NO`), MAX(`INV_NO`) WHERE `INV_DATE` = '2008-09-30'
I have check so many times on the syntax and cannot pin point the mistake.
Please help me on the matter
Thanks a million

Regards
Muraly
0
 

Author Comment

by:Muraly
ID: 22620687
Dear Sir,

My mistake i jow what was the error, there were no FROM, means the table name.
Below is the correct one
SELECT MIN(`INV_NO`), MAX(`INV_NO`)from pos_ord_info WHERE `INV_DATE` = '2008-09-28'
Thanks a milllion for all the help

Regards
Muraly
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now