-
indexes
I have a simple table, few records for testing. there 4 indexes defined.
when issuing:
SELECT reg_data FROM test_table
but the following:
SELECT MAX(reg_data) FROM test_table
gives no result neither error msg
Questions:
1.How to retrieve the maximum (last) value of an autoincrement field?
2.where to find the result codes
of a search.?
I need to know if there was no data found or if something else happened
3. if no INDEX claused is specified,
does mysql use the PRIMARY or uses no indexes?
thanks a lot!
-
Please have a look at the MySQL Documentation dealing with indexes.
Also have a look at the GROUP BY documentation to see how MySQL uses MIN() and MAX().
Could you perhaps give us the structure of the table?
Cheers
-
table structure
very simple,
a multipart key:
date, unit, code
I created 3 indexes, one for each.
primary key is an autoincrement
the mysql docs are very difficult to
get the basics.
for example: do I have to place the
USE INDEX every time I want to seek
for one special record?
WHY I get errors on WHERE clause
when saying: field = $var,
WHY the $result of a query can be ok
but no rows are retrieved?
There are no practical examples,
it onle covers the wide sintax.
Is there any basic approach just
to read/write single records
with unique keys (single or multipart)
I just need to create customer records,
and retrieve them one by one
for update.
I don't need any sofistication,
just the very basic I write one rec
the I find it. that's all
thanks a lot!
-
I am no expert, and I have spent hours in pursuit of the manual. It is not always the clearest place, but it is definitive. While my experience is much lower then many of those that I know are on these forums let me offer something here in as a small token of respect for those who have helped me in the past.
Questions:
1.How to retrieve the maximum (last) value of an autoincrement field?
You are looking to use:
mysql_insert_id()
This returns the last/insert id from a autoincremented field as you are indicting above.
If you are using say php after you have added a record do something like:
connect to your database and then
Code:
$lastrecid = mysql_insert_id();
echo "The last record is ".$lastrecid;
This will return the value of the last record added.
2.where to find the result codes
of a search.?
I need to know if there was no data found or if something else happened
There are a variety of ways you can determine if a search has returned results. Here is one php example that might put you on track;
Code:
sql = "SELECT * FROM test_table";
$dispcount = (mysql_query($sql)) OR DIE (error());
if ($myrowcount mysql_fetch_array($dispcount))
{
$counted_recs = $myrowcount["reccount"];
}
You can test counted_recs, display it, use foreach or do/while to display the returned rows if the count is >0, or if the query returns zero you can ...
3. if no INDEX claused is specified,
does mysql use the PRIMARY or uses no indexes?
You simply need to construct your query. MySQL will attempt to optimize the use based on the indices available.
I sincerely hope that this is of some assistance.
Best,
TBull
PS: sorry about the formatting the text entry window is not the easiest in this forum.
PSS: If this helps please remember to try to help someone else when you can. Knowledge is a wonderful thing, it grows with use. Make it easy for others to gain.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|