?
Solved

FIRST Statement in MySQL

Posted on 2008-09-30
8
Medium Priority
?
351 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
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 143

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:
Aleksandar Bradarić earned 200 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
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 
LVL 143

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:Aleksandar Bradarić
ID: 22604200
Both should work. Can you post your existing PHP code?
0
 
LVL 17

Expert Comment

by:Aleksandar Bradarić
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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

801 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