Solved

FIRST Statement in MySQL

Posted on 2008-09-30
8
350 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 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
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 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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

707 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