Solved

FIRST Statement in MySQL

Posted on 2008-09-30
8
339 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 5 124
Need help with a query 6 55
SQL Server 2008 R2 - Execution Plan 3 31
SQL Select Query help 3 32
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…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

744 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

10 Experts available now in Live!

Get 1:1 Help Now