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
Solved

FIRST Statement in MySQL

Posted on 2008-09-30
8
343 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 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:
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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: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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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