473,738 Members | 3,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get the First record

Hi all,

Is there a MySQL function to get the first record through a query? I would like to open a page of
client records with the first one shown. The other records can be accessed from a hyperlinked list.

Thanks for any advice,

Rick
Jul 17 '05 #1
17 4474
Rick wrote:
Is there a MySQL function to get the first record through a
query? I would like to open a page of client records with the
first one shown. The other records can be accessed from a
hyperlinked list.


Define "first record" :)

There is no such thing as far as the database is concerned. If you want
to retrieve a single record from the database say so in the query:

select *one* record from the database:
select <field, list> from <tables> where <conditions>
LIMIT 1

select *the first record* from the database
select <field, list> from <tables> where <conditions>
ORDER BY <sort, fields> limit 1
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
If you only want to return the first row from an unknown number then add
"LIMIT 1 OFFSET 0" to the SELECT statement. Check out the syntax at
http://www.mysql.com/documentation/m...ax.html#SELECT

--
Tony Marston

http://www.tonymarston.net
"Rick" <RB@newsgroup.n et> wrote in message
news:11Y0c.9775 8$Xp.432840@att bi_s54...
Hi all,

Is there a MySQL function to get the first record through a query? I would like to open a page of client records with the first one shown. The other records can be accessed from a hyperlinked list.
Thanks for any advice,

Rick

Jul 17 '05 #3
I noticed that Message-ID: <11Y0c.97758$Xp .432840@attbi_s 54> from Rick
contained the following:
Is there a MySQL function to get the first record through a query? I would like to open a page of
client records with the first one shown. The other records can be accessed from a hyperlinked list.


Data is not stored in any particular order in a database. Therefore the
concept of 'first record' is meaningless.

Presumably you mean the oldest record. Either use a field containing a
timestamp or a primary key that auto increments and order the results by
one of those.

For example

$result = mysql_query("SE LECT * FROM table ORDER BY id ");
//default is ascending

//to fetch the first record
$myrow = mysql_fetch_arr ay($result)
print $myrow["fieldname1 "];

//loop through rest of records
while($myrow = mysql_fetch_arr ay($result))
{
//do stuff with records
}


--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #4
Geoff Berrow wrote:
I noticed that Message-ID: <11Y0c.97758$Xp .432840@attbi_s 54> from Rick
contained the following:
Is there a MySQL function to get the first record through a query? I
would like to open a page of client records with the first one
shown. The other records can be accessed from a hyperlinked list.


Data is not stored in any particular order in a database. Therefore
the
concept of 'first record' is meaningless.


Actually, this is not always true... While data may be stored unordered, the
data may also be stored in an ordered manner, usually in the order defined
by an index on the relation.
Jul 17 '05 #5
in which case you still are talking about random records, but indexed by an
indexfield....
First record, still is something undefined, whereas record with lowest
indexnumber might have a "first record" feel to it.

Michel

"Agelmar" <if**********@c omcast.net> wrote in message
news:c2******** *****@ID-30799.news.uni-berlin.de...
Geoff Berrow wrote:
I noticed that Message-ID: <11Y0c.97758$Xp .432840@attbi_s 54> from Rick
contained the following:
Is there a MySQL function to get the first record through a query? I
would like to open a page of client records with the first one
shown. The other records can be accessed from a hyperlinked list.
Data is not stored in any particular order in a database. Therefore
the
concept of 'first record' is meaningless.


Actually, this is not always true... While data may be stored unordered,

the data may also be stored in an ordered manner, usually in the order defined
by an index on the relation.

Jul 17 '05 #6
Agelmar wrote:
Actually, this is not always true... While data may be stored unordered, the
data may also be stored in an ordered manner, usually in the order defined
by an index on the relation.


The key word there is *may*.

And the DB server *may* return the records in the order they are stored.
Suppose you have a table with a ID (auto_increment primary key) column.

You have no guarentee that
"select id from table where id between 7890 and 7891"

will return the record with ID 7890 before the other record; the result
*could* very well be
+------+
| ID |
+------+
| 7891 |
| 7890 |
+------+
and *may* even change between calls to the same query!

So, if need the records returned in a specific order, specify that
order in the select command.
<?php
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 0;
$sql = 'select id, name, email from people limit ' . ($page*20) . ', 20';
// ...
?>

does *NOT* guarantee you will not see the same people on page 7 as you
saw on page 6 (or does it?).
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #7
Pedro Graca wrote:
Rick wrote:
Is there a MySQL function to get the first record through a
query? I would like to open a page of client records with the
first one shown. The other records can be accessed from a
hyperlinked list.

Define "first record" :)

There is no such thing as far as the database is concerned. If you want
to retrieve a single record from the database say so in the query:

select *one* record from the database:
select <field, list> from <tables> where <conditions>
LIMIT 1

select *the first record* from the database
select <field, list> from <tables> where <conditions>
ORDER BY <sort, fields> limit 1


What I want to do is fill a page that displays record details with some data even if the user did
not select a customer id. I just want to grab one record...either first by id or last name (asc),
but one record only.

The 'Limit' clause as suggested by both Pedro and Tony appears to be what I want.

Thanks,

Rick
Jul 17 '05 #8
I noticed that Message-ID: <JB41c.166553$u V3.715478@attbi _s51> from Rick
contained the following:
What I want to do is fill a page that displays record details with some data even if the user did
not select a customer id. I just want to grab one record...either first by id or last name (asc),
but one record only.
Yes but you also said,

"The other records can be accessed from a hyperlinked list."

I assumed you wanted to show the full details of one record and possibly
a summary of all others such that you could simply click them and get
the details of that record. How are you going to create the list if you
have only accessed one row using LIMIT ?
The 'Limit' clause as suggested by both Pedro and Tony appears to be what I want.


Not if I have understood your scenario correctly.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #9
Pedro Graca wrote:
Agelmar wrote:
Actually, this is not always true... While data may be stored
unordered, the data may also be stored in an ordered manner, usually
in the order defined by an index on the relation.


The key word there is *may*.

<snip>
No arguments. I was just responding to the specific sentence "Data is not
stored in any particular order in a database."
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8791
by: Richard C Buchanan | last post by:
I have a table as follows: - user_id (key) - user_email_address (text) - user_request_date (text) - user_sent_date (time/date) An automated macro will run every 5 minutes and needs to run a SQL UPDATE that:
4
12995
by: KJ | last post by:
We use a third party software package for acctg that limits us on field size - as a result, we at times have to enter an item into the app multiple times in order to get all the information. I then created an Access DB that is linked to the information and have combined all data onto one record so that we can export to excel. The next step for me is to eliminate all the other instances of this particular item, leaving me with only the...
3
2232
by: Jason A. Thompson | last post by:
Dear Access Gurus, I have a database which I hoped to use to administer questionnaires, or rather that someone who knows nothing about Access could use to administer them. Each q'aire item is on a different form and I dropped in command buttons on each to move forward and backward through the "pages" of the q'aire. Problem is, the first record in the common underlying table is overwritten each time we go through the q'aire. (The code to...
6
5099
by: neptune | last post by:
I must be missing something obvious. I have 3 fields and sample data. 7890 26592 7/15/2003 7890 13645 10/6/1999 7890 58741 6/21/1992 I want to select only the most recent record. It is sorted descending by in the query and subquery. In the query Total, I select Group By , First and First
5
5259
by: tdmailbox | last post by:
I have a form with a child form. In the child form there is a list of names that can grow quite large. On the parent form I want to display the first name from the child form. I set up a test box that is populated with the code =subfrm_media_review_sec_party.Form!first_name & " " & subfrm_media_review_sec_party.Form!last_name It works except that when I flip through the names it populates the parent form with the name of what ever...
10
3734
by: Lyn | last post by:
I have a form set to Single Form mode with which I can cycle through the records in a table via Next and Previous buttons. To avoid users pressing the Previous button on the first record and the Next button on the last record, I would like to disable one or both buttons when the first and/or last record is displayed. I am not sure how to do this when the RecordSource is simply the table. I know that if the record source were a...
1
1424
by: Karthiga1984 | last post by:
Hi Table Structure company name Phone No Products Example Company Name Phone No Products
1
6482
by: Hubert Wisniewski | last post by:
Hi, I have a problem with first record in my table. I put the data to the table and it's ok, but if I add second row to the table the first record is updated (and has the same value as the second row). I use the same code for three tables in my application and it works without any problem with this one exception. If I have the first item the another I can add without any problem.
2
6390
by: ofuuzo1 | last post by:
Hei, I have the following xml file and I have tried to write xslt to extract only the values of the first "record" node. It does not work. I need some help. I used ---- to represent indent. Xml: <?xml version="1.0" encoding="UTF-8"?> <OAI-PMH xmlns="http://www.openarchives.....OAI/2.0/OAI-PMH.xsd"> ---<responseDate>2008-02-19T12:54:06Z</responseDate> ---<request xmlns="" verb="ListRecords" ......o.no</request>
0
8968
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9259
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.