Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    MYSQL




Retrieve Most Recent Rows


I have a simple table with four columns. ID (auto_increment), username, score, and date (unix timestamp). How could I, if possible, get the past 10 scores of each unique username? So if there were 15 different usernames, I would get 150 rows returned (assuming all of them had played 10+ games). Can this be done in a single query or do I need to run a query for each username?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Trying To Retrieve Most Recent Record Per Date
I have the following query which is retrieving a set of data it is
almost what I want but I can not manage to get the result I desire.

SELECT r1, r1_dev, r2, r2_dev, date, time
FROM output
WHERE output.id_modality = '1' AND output.id_linac='2'
ORDER BY output.date DESC

'r1','r1_dev','r2','r2_dev','date','time'
'37.500','0.334449476181','[NULL]','[NULL]','2006-07-27','15:00:00'
'50.000','0.334449476181','37.470','0.0000364374', '2006-07-27','11:26:00'
'50.000','0.334449476181','37.470','0.0000364374', '2006-07-27','11:26:00'
'40.812','0.8538683','0.000','0.0000000000','2006-05-12','08:50:00'
'41.580','2.7517359','40.370','-0.2383940000','2006-05-12','08:45:00'
'40.756','0.8155671','0.000','0.0000000000','2006-05-12','15:00:00'
'37.952','-0.472445','0.000','0.0000000000','2006-05-12','14:53:18'
'38.010','-0.3203424','0.000','0.0000000000','2006-05-12','14:52:33'
'39.488','3.3474615','37.916','-0.7667557000','2006-05-12','08:35:43'
'39.650','3.7714458','38.020','-0.4945683000','2006-05-12','08:22:38'
'40.330','-0.2382025','0.000','0.0000000000','2006-05-12','15:00:00'
'41.330','2.2354728','0.000','0.0000000000','2006-05-05','00:00:00'
'39.220','2.8528707','0.000','0.0000000000','2006-05-05','00:00:00'
'40.696','0.8814325','0.000','0.0000000000','2006-04-28','15:56:00'
'41.000','1.635019','0.000','0.0000000000','2006-04-28','15:55:00'
'38.380','0.8642144','38.400','0.9167752000','2006 -04-28','15:56:10'
'37.970','-0.2132824','38.510','1.2058597000','2006-04-28','15:49:23'

From the set above I would like to retrieve the latest measurement per
date but if I try to group by date (like below) I always get the first
result instead of the latest result.

SELECT r1, r1_dev, r2, r2_dev, date, time
FROM output
WHERE output.id_modality = '1' AND output.id_linac='2'
GROUP BY output.date ASC
ORDER BY output.date DESC

'r1','r1_dev','r2','r2_dev','date','time'
'50.000','0.334449476181','37.470','0.0000364374', '2006-07-27','11:26:00'
'39.650','3.7714458','38.020','-0.4945683000','2006-05-12','08:22:38'
'39.220','2.8528707','0.000','0.0000000000','2006-05-05','00:00:00'
'37.970','-0.2132824','38.510','1.2058597000','2006-04-28','15:49:23'

Retrieve Most Recent Records From Database Sorted By String Value
I'm having a problem with a simple select query. I've got users
uploading data into a database. I want to do something that seems as if
it should be really simple, but it isn't so far.

Basically, I want to retrieve the latest 12 records from the table,
sorted by the date-time field (uploaddate) then by a varchar field
(name). Here's the SQL that I'm using:

select * from tblcontent
where filetypeid=1 and release='Y'
order by uploaddate desc, name limit 12;

And here's the table schema:

Field,Type,Null,Key,Default,Extra
ContentID,int(3),,PRI,NULL,auto_increment
Name,varchar(50),,,,
Filename,varchar(100),,,,
Thumbnail,varchar(100),,,,
FileTypeID,int(11),,,0,
UploadDate,datetime,,,0000-00-00 00:00:00,
Description,text,,,,
ContributorID,int(10) unsigned,,,0,
Release,enum('Y','N'),YES,,N,

The problem I'm running into is that while I am retrieving the most
recent 12 records, it's not sorting by the varchar field. Instead, the
'Name' field seems randomly sorted. If I change the sort order (name,
uploaddate desc), I don't get the records that I want.

This seems like it should be something very simple to do, but it's
driving me nuts and I really have no idea how to resolve the problem. Code:

Display 4 Most Recent Rows
I need to display the next 4 upcoming events (from the current date) in our events database...

SELECT * FROM events WHERE eventdate ??? LIMIT 4

Delete Oldest Rows Keeping 10 Most Recent, How?
Example: There is a table (NEWS). In that table I want to automatically delete rows so I'll always have 10 rows with the most recent news. The oldest news should be deleted keeping the 10 most recent.

TABLE NEWS is something like ID, news, date. I can't figure out how the query should look like. Any ideas?

Retrieve Number Of Rows
I've got a large table with a lot of entries. only two fields, one's the key (which auto incs) and the other's a text field...if I want to just retrieve the number of rows in the table, what's the best way to do this?I know I could tell mysql to sort the table by the key row and then take the first one, but wouldn't this make it analyze the entire table (which would waste resources, especially considering that this table will have thousands and thousands of entries)? what's a better way to do it?

Retrieve Everything AND Count Rows In One Query
set rsminmax = con.execute("SELECT * FROM `minirules_minmax` where RuleId = '" & contractId & "'")
set rsminmax2 = con.execute("SELECT COUNT(*) FROM `minirules_minmax` where RuleId = '" & contractId & "'")


Is there any way to do this in one SQL query?

Efficient Ways To Retrieve Specific Rows...
First, please excuse the fact that I'm a complete MySQL newbie.

My site used forum software that I wrote myself (in Perl) which, up until
now, has used flat files. This worked fine, however lately I've been wanting
to do more stuff with user accounts, and had been eying MySQL for over a
year.

Finally I've decided to start off small by converting the forum's account
system to a MySQL database (and convert the rest later after I'm
comfortable). So far everything is working fine, and I've figured out how to
create the table, insert records, modify records, and so on.

However I had a question on what was the most efficient way to retrieve
information about a user as I read through the flat file containing
messages.

As each message is read I want to find that user's relevant information,
build it into my output, then continue on to the next message. Now here's my
problem. Since I'm reading a flat file in a way that was once trying to be
somewhat memory efficient (on really slow server way back when, trying to
avoid arrays and hashes) I'm finding that I'm having to send separate
questions to MySQL as each message comes up. Say from 1 to 20 very simple
questions to complete printing the page. Also, sometimes the questions might
be repetitive - since I'm not storing any of the results in memory, if a
user appears twice I ask about it twice.

Would I really be better off trying to find a way to consolidate all
distinct users into a single question? Or is MySQL efficient enough that
this isn't really much of a concern?

Efficient Ways To Retrieve Specific Rows...
My site used forum software that I wrote myself (in Perl) which, up until
now, has used flat files. This worked fine, however lately I've been wanting
to do more stuff with user accounts, and had been eying MySQL for over a
year.

Finally I've decided to start off small by converting the forum's account
system to a MySQL database (and convert the rest later after I'm
comfortable). So far everything is working fine, and I've figured out how to
create the table, insert records, modify records, and so on.

However I had a question on what was the most efficient way to retrieve
information about a user as I read through the flat file containing
messages.

As each message is read I want to find that user's relevant information,
build it into my output, then continue on to the next message. Now here's my
problem. Since I'm reading a flat file in a way that was once trying to be
somewhat memory efficient (on really slow server way back when, trying to
avoid arrays and hashes) I'm finding that I'm having to send separate
questions to MySQL as each message comes up. Say from 1 to 20 very simple
questions to complete printing the page. Also, sometimes the questions might
be repetitive - since I'm not storing any of the results in memory, if a
user appears twice I ask about it twice.

Would I really be better off trying to find a way to consolidate all
distinct users into a single question? Or is MySQL efficient enough that
this isn't really much of a concern?

Query To Retrieve The Last "X" Rows
I need create a query to retrieve the last 10 rows of my table.....

Most Recent Value
I've become rather rusty with the old SQL statements, and would really appreciate your help with the following.

Assume I have one table (tbldata):


dataID | date | configID | value
1 | 3 | 1 | 0.75
2 | 5 | 3 | 0.15
3 | 5 | 4 | 0.60
4 | 6 | 1 | 0.87
5 | 9 | 3 | 0.29
6 | 10 | 1 | 0.52

Most Recent Date.
I have a date_added field in the database. But I always want to get the rows that have themost recent date with time

('clk0h4tski156pgfgo4kth21b6', '', 'Place_Card_personalised', 'Z/X', 2, ད.00', 'chris', ��-05-20 10:37:07'),
('clk0h4tski156pgfgo4kth21b6', '', 'Day_Invitation', 'M', 2, ྊ.00', 'chris', ��-05-20 10:37:07'),
('clk0h4tski156pgfgo4kth21b6', '', 'Day_Invitation', 'M', 2, ྊ.00', 'chris', ��-05-20 10:36:37');
Will the following query do what I want it to do?

SELECT DISTINCT(date_added), SUM(price) FROM cartTemp WHERE `cart_id` = '$cart_id' AND `username` = '$username' GROUP BY price

Updating Most Recent/last Row
This is for a directory and the table Dir holds the selected plan of each member. The table contains a history of the plans (inserted on each selection) so what I need to do is update the last row of Dir.DirID.

Every time 'Posting' value is echoed on the page with query 'Listings' (two seperate tables from Dir - one for runtime and one for the actual postings (a foreign/primary key) - then Dir.Dview is incremented as a basic hit counter with the query Listings higher on the page.

What is the most reliable way of updating the last row of Dir.DView where DirID is primary?

note: query 'Listings' uses SELECT max But experimenting with this before, I hessitate to use SELECT max for an update.

<?php echo ($row_Listings['Posting']);
$query_updateSQL = sprintf
("UPDATE Dir SET Dir.DView = (Dir.DView+1) WHERE DirID = %s",
$colname_Listings);
$result = mysql_query($query_updateSQL);
?>

Query Most Recent Row For Each IP?
Anyone know off the top of their head how i'd run a query to get the most recent entries (datetime) for any given IP? ....

Getting Most Recent Record
Given a table that has the following fields:

create table WAGE_RATES(
EMPLOYEE_ID int unsigned references EMPLOYEES,
DATE date,
HOURLY float(5,2),
WEEKLY float(5,2),
OTHER float(5,2),
index(DATE)
);

I want to run a SELECT query that uses the EMPLOYEE_ID number to compare all available records and return only the most recently entered record making use of the DATE field. What does the query look like? How do you make the database return a record based on the most recent date?

1 Table -> Get Most Recent Row For Each Id
I have a problem that can be summarized with a simple table having the
following 3 columns:

timestamp
userid
status

The table is constantly being updated.

I'd like to get the most recent row for each userid present in the
table?

What pray tell is the trick?

I tried using GROUP BY, but it would only return the 1st occurance of
each userid (I want the last).

Sql To Get Most Recent Records
How would I write the query for mySQL to get all the records in a table that
were written in tha last 10 minutes?

I have a timestamp field (fldTime) that automatically inserts the curent
time when the record is inserted, but I'm unsure how to write a query that
would only get records from the last 10 miniutes.

Sort Asc W/ Most Recent
I want to display the five most recent rows in my table (there is a timestamp), but sorted in ascending order.

the problem is that when i call

SELECT * FROM spam ORDER BY time ASC LIMIT 5

it shows the first five entries in ascending order, but i want the last
five.

needless to say, it works fine with descending order..

Recent Entries
I have a table containing a "time" and an "author" column. How is it possible
to select the 10 most recent entries, but sorted by "author"?

Getting The Most Recent Record
Given a table that has the following fields:

create table WAGE_RATES(
EMPLOYEE_ID int unsigned references EMPLOYEES,
DATE date,
HOURLY float(5,2),
WEEKLY float(5,2),
OTHER float(5,2),
index(DATE)

Recent Record
Basically what i want to do is create an SQL string that searches the table for a specific userID, THEN finds the most recent record of the userID (according to my datetime field which is called transdate).

Im Using ASP to connect to a MySQL database.

i've looked all over the net trying to find out how, also i dont really know which forum this should be in (either mysql or asp?).20

Most Recent Entries
I have a table containing a "time" and an "author" column. How is it possible
to select the 10 most recent entries, but sorted by "author"?

Recent Primary Key
I am trying to get my php page to select the most recent addition to a database under a certain username sorted by most recent primary key, but I am unsure on the SQL syntax to accomplish this. What I am trying to do is some thing like:
Code:
update table_name set title = new_title and content = new_content where username = username sort by primary key most recent;
Is this possible and if now do you have another idea of how I can accomplish something similar?

Get Most Recent Version Of An Element
I'm new to mysql and I was wondering if I could trouble some of you for
help. I have a table in my database that may contain multiple versions
of the same element as different rows.

I wanted to use the following query to group the rows by element with
"group by" and then use the "having" to get the most recent version of
each element, which would then be returned in "select" but this doesn't
seem to be working. Any elements with multiple versions are simply not
returned.

I could swear that I have used a similar approach in the distant past
with other databases and it worked, though, so I must be bollocksing
this up pretty badly while attempting to work off of what I
remember...

Left Join To Get The 1 Most Recent
Firstly table structure - 1 user has multiple status records. When a new status record is created it gets the current datetime inserted into 'date_created'.

user
user_id
site_id

status
status
notes
date_created

I wish to display a list of all users and show beside them their current/most recent status record. Here is my code currently:

SELECT user.*, status.date_created, status.status, status.notes,
DATE_FORMAT(status.date_created,'%l:%i %p') as last_updated_time,
DATE_FORMAT(status.date_created,'%e/%c') as last_updated_date
FROM user
LEFT JOIN status ON status.user_id = user.user_id
WHERE user.site_id = 1
GROUP BY user.user_id
ORDER BY
CASE user.user_id WHEN 8 THEN 0 ELSE user.user_id END

Currently via the LEFT JOIN and GROUP this does display a list of all users with 1 status record per user but it's simply the first status record in the table (ordering by id i guess), not the most recent. How can I get it to display the most recent instead, based on date_created. I've tried adding ordering to the left join but this returned an error.

Distinct, Most Recent Sort
Does anyone know how to do a sort to find the most recent distinct records.

We have records with equipment, and activities the equipment was used for,
but I need a distinct list of where the equipment currently is, if I do a
distinct ...order by date, it will perform the distinct first, ahead of
ordering.

Showing 5 Most Recent Entries
I'd like an area on my site where the 5 most recent entries into the database are displayed in a list, with the top result being the most recent of all.

For this I was planning on doing something like querying the id field of the database to find the five highest numbers only and then echoing them out in descending order.

This however is not something I have been able to find any information on in my searches.

Retrieving Most Recent Datestamp Row
If you remember my post from a few days ago, this is the table structure that I'm now using (thanks CYoung and TonyGroves):

stamp DATETIME not null primary key,
year int(4) not null,
month int(2) not null,
day int(2) not null,
hour int(2) not null,
minute int(2) not null,
reading float(10,6) not null



How would I go about retrieving the results that have the most recent and most distant DATETIME  from the above table? These are not necessarily the first and last rows entered in the database table, as the order in which files are parsed and entered into the database may not be chronological.

Apologies if this is remedial but I'm fairly new to sql.

I also need to fetch results by descending DATETIME. I'm guessing that this will do it:

"select * from siteTable
 where stamp between $datetimeA
 and $datetimeB
 order by stamp desc"

I won't be able to test it out until tomorrow night. Can I do the 'order by desc' thing with datestamps?

Select Most Recent From A Group
Hello I am having troubles with a query I am trying to make.
I have a table to keep notes on customers
note_id - primary
biz_id
date_of_interest
notes

I want to grab the biz_id and notes of every record that has a date_of_interest before or on today's date. The problem I am having is if one customer has multiple notes such as:

3, 1233, 2006-05-02, note
8, 1233, 2006-06-28, note
13, 1233, 200-07-24, note

he will get selected from my query since two of his previous notes have a date_of_interest before today but I really only want to care about the most recent of notes so he shouldn't get selected. Is there a way to do this in the query or should I add another field to the database to mark it as the most recent.

Get GROUP To Display Most Recent Entry?
I'm pulling in info and Grouping by my column that stores "project names".
The Grouping is successful, but rather then displaying the most recent entry for the GROUP, the first entry made is displayed.

I would like the most recent entry to represent the group.

I would guess that this needs a MAX function run on my column that keeps the entry_date but I can't seem to get this to work.
Each time I apply the MAX function I end up limiting my results to 1 entry...not what I want.

This is the query I'm starting with:
MySQL
SELECT                              d.entry_id    as prj_id,d.field_id_1  as prj_name,d.field_id_5  as prj_thumb,d.field_id_15 as prj_image_type,d.weblog_id,t.entry_date,t.url_title as prj_url,t.status as prj_status,c.cat_url_titleFROM    exp_weblog_data dLEFT JOIN    exp_weblog_titles t    ON    d.entry_id =  t.entry_idLEFT JOIN    exp_category_posts cp    ON    t.entry_id = cp.entry_idLEFT JOIN    exp_categories c    ON    cp.cat_id =  c.cat_idWHERE    t.status = 'open'    AND    c.cat_url_title = '{segment_4}' // variable grabbed FROM URLGROUP BY    d.field_id_1ORDER BY    t.entry_date    ASCLIMIT 16

Displaying Only The Most Recent Added Files
Can someone please tell me how I can display only the most recent pdfs or Word documents that are added to a database?

Grouping Fields And Getting Most Recent Date
I have a table like:

table_id
table_foreign
table_datetime

I'd like to select the highest datetime for each foreign. So far I've tried something like this...

SELECT
*
FROM
table
GROUP BY
table_foreign
ORDER BY
table_datetime DESC

Unfortunately, the ordering only works on the grouped resultset, not that the values of the dates.

Join/Select Only Most Recent Record
I have two tables. The first is a list of customers and the second is a list of sales invoices. I want to link the 2 tables but only select the newest/most recent invoice. There can be many invoices for a single customer.

Customer Table
CustomerID integer (primary key);
CustomerName char

Sales Table
SaleID integer (primary key)
CustomerID integer (key from customer table)
SalesDate Date
SalesAmount integer

Here is what I have so far:

select customertable.customername, salestable.salesdate, salesamount from customertable
inner join salestable on customertable.customerid = salestable.customerid

How can I return only a single record for each customer (the most recent/newest sale)?

Max(date) Per KeyField - Get Most Recent Data
I have a large list of daily stats from various systems, i.e.

Table Stats
SystemID | tagID | dtStamp | Value
S001 : T100 : 2006-03-23 : 50
S001 : T101 : 2006-03-23 : 2
S001 : T100 : 2006-03-24 : 53
S001 : T101 : 2006-03-24 : 5
S001 : T100 : 2006-03-25 : 60
S001 : T101 : 2006-03-25 : 8
S001 : T100 : 2006-03-26 : 65
S001 : T101 : 2006-03-26 : 12
S002 : T100 : 2006-03-23 : 10
S002 : T101 : 2006-03-23 : 1
S002 : T100 : 2006-03-24 : 12
S002 : T101 : 2006-03-24 : 2

I need the date of the last record of data for each site for each tag. (i.e. the most recent data for each site)

I tried using max(dtStamp), but it found the biggest date in the table and tied it to every system/tag the same. i.e. it showed 2006-03-26 for S002/T101, even though I know I don't have data for that site on that day.

Group/Join - Wish To View Most Recent...
I've been trying to sort this out for over 2 hours and I can't get it to work! What I want is for the code at the base of this post to list each of the forums with the most recent topic details. My problem is that it doesn't choose the most recent post, it chooses the first.

I've tried:

- changing 'forums_topics.topic_time' to 'MAX(forums_topics.topic_time)' [returns the MAX value, but not the corresponding topic_id/title - it still returns the first topic_id/title!]

- adding 'forums_topics.topic_time DESC' to 'ORDER BY' [no effect]

- adding 'forums_topics.topic_time' to 'GROUP BY' [this lists them successfully, and with this the ORDER BY has an effect, but I don't want to list all topics, just the most recent]

- adding subqueries (couldn't get to work)

- adding 'HAVING topic_time = MAX(forums_topics.topic_time)' after 'GROUP BY forums_forums.forum_id' [which returns only the forums with a single post] .....

Query To Display A Record By Recent Time
Many users uploaded their files to my mysql table through php script,
my table having the details of uploading time, file name, & uploader name.

i need to find the recent uploaded file for all uploaders.

i tried with this query,

select file_name,uploded_by,MAX(date_time) from upload group by uploded_by;

it is giving the recent time, but it is not giving the latest file, it is showing first uploaded file.

Recent Upgrade From 4.0.25 To 5.0.27 LEFT Join Problem
PHP

SELECT...
FROM tournament_results tr, tournament t
LEFT JOIN tournament_results tr2 ON tr.id = tr2.id
AND tr2.earnings >0
WHERE tr.memberid =9
GROUP BY tr.memberid

Here is the Error

PHP

Unknown column 'tr.id' in 'on clause'

Problem is tr.id does exist.

Return Row With Most Recent Timestamp In A Group By Device
I'm trying to build a query to return the row with the most recent timestamp for each device in a table.

CODESELECT (Fields)
FROM (Database)
WHERE (Conditions)
GROUP BY deviceID
HAVING MAX(timestamp);

Deleting All Records Exept The Most Recent From Different Users
There are multiple users listed in the table and each user has multiple records.

I would like to delete every record from each user with the exception of the most recent from each user.

The SQL statment I use is this..

DELETE FROM `phpbb_adr_battle_list` WHERE `battle_id` != <users most recent battle ID> and `battle_challenger_id` = <user id>

battle_id is an autoincrementing number so I know the highest number a user has is their most recent battle

I manually look at each user, find the highest battle ID they have and use it in the statement.

Is there a way to do this automatically? So it would search for the highest battle_id for each user and delete the rest?

Most Recent Results, Without Using Subqueries Or Temp Tables.
I have a table whose schema is essentially as follows:

Results(name varchar(20), version varchar(20), configuration varchar(20), status varchar(20), datetime timestamp(14))

Essentially, what I would like to accomplish is to get the most recent record for name, and also for the combination of name and version.

I'm using MySQL 4.0.12 and therefore do not have access to subqueries, and would like to avoid using a temp table, which I am doing right now with limited success and considerable overhead.

I've also tried using a group by statement and using max(datetime) to get the most recent timestamp, but I end up getting the right timestamp, but the incorrect values in all of the other columns.

Join 2 Tables And Select Only Most Recent Records
I have been wrestling with a way to select only the most recent records for a group of clients without using a subselect. I have two tables: cdp_clients and cdp_level_records related by 'admitid'. For each cdp_client there are multiple cdp_level_records, each with a different 'level_date'. I want to select only the most recent cdp_level_record for each client in cdp_clients.

Recent Mysql Upgrade, Ignores NOT NULL Declarations?
Can anyone tell me why CREATE TABLE and ALTER TABLE ignore the NOT NULL clause on my mysql 5.0.19 on windows xp?

This is problematic because I want to migrate some data to a older version who's NOT NULL fields are behaving as I would expect them to triggers errors when I try to import data with NULL fields. It can be fixed with a search and replace but I'd like to learn more about this problem. Any info?

Coparing Dates From Two Tables Output The Most Recent Record
How would I be able to query my database and get the record that is the most recent from two tables.

select m.multimedia_ID, m.ReleaseDate, m.status,
       News.ArticleID, News.ReleaseDate,News.status
       from multimedia, NewsFeatures
       where m.ReleaseDate <= now() OR
             m.ReleaseDate <= now()
       
Output:
240 01-09-06 first  

Retrieve Cardinality?
I was wondering it is possible to retrieve the cardinality from an index through a mysql query in a php script? I am trying to find the number of unique items from tables with 10+ million rows and do not want to have to calculate them each time the page loads.

Insert And Retrieve...
Can I INSERT a record in a Table and retrieve the Pkey of the added record in the same QUERY or how can I use 2 Querys in the same call?

How To Retrieve A Value From Column ?
i have a table here called my_table .

my_table;
+----+-----------+-------------------------------------------------------------+----------------+
| id | type | data | last_update |
+----+-----------+-------------------------------------------------------------+----------------+
| 1 | employee | a:2{s:1:"name";s:2:"ganesh";s:3:"phone no";s:4:"98989898"; } | 20060309034040 |
| 2 | department | a:2{s:1:"name";s:2:"ece";s:3:"no profs";s:4:"20"; } | 20060309034040 |
| +----+-----------+-------------------------------------------------------------+----------------+

data column is of type text. is it possible to create this kind of table? how do i create this type of table ? and if above is the case how do i retrieve name of the employee . generating value for data column is through any script/logic or is there any mysql systax. if syntax does not exit ? then will i have to retrive using some logic.

Retrieve Only Top Record Using IN
I have 'Order' table which has many account nos for a particluar tel no. So if i query:

select * from orders where telno = '1234' order by inid;

Retrieve Autoincrement Value In PHP
I want to display an autoincrement value after a record has been added in a MySQL database. In MySQL I can do :

INSERT INTO table (ID,field) VALUES(NULL,'text');
SELECT LAST_INSERT_ID();

However how do I get this value on screen in a PHP-program?

The update in PHP-code looks like:
$table_add = "INSERT INTO table (ID,field) VALUES (NULL, '$field')";
$bool = mysql_query($table_add);

and than I want to show the record-ID like :
echo "Thanks $text, record ID: $ID";

If i do a seperate query, the last_insert_ID value renders 0 (zero), so it must be done within the same query. What should the query look like and how to display the result in PHP?

Retrieve Substring
i have created a website running on MySQL and have a description field in one of that tables.  I would like to display, say the first 100 words from this field with a linked more button allowing you to go and view the rest. Can anyone tell me if this is possible in SQL or do i require to bring the whole field back?

Retrieve Records
I have 2 tables:
1. Price table: with Price_Id(PK), Price 2 columns
2. Booking table: with Booking_Id(PK) ,Booking_Date,Price_Id(FK)

now I want to retrieve all the records in price table that are not referenced by booking table (i.e. not booked).


Copyright © 2005-08 www.BigResource.com, All rights reserved