[thelist] mySQL- how to test if table contains data

BT Bigpant bigpant at btinternet.com
Wed Feb 6 04:07:01 CST 2002


Another thought - if you know the date in question, use

$sql="SELECT COUNT(*) AS count FROM $database.$timetable WHERE Truckip like
'$truckip' AND TIME=$required_date GROUP BY TIME";

This will tell you how many columns contain data, without the problem of
getting a null recordset.

Phil Parker

-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]On Behalf Of Richard Bennett
Sent: 06 February 2002 09:33
To: thelist at lists.evolt.org
Subject: [thelist] mySQL- how to test if table contains data


Hi,
I am a mySQL beginner, doing someone else's work right now.

What I have is a table that stores (lots of) data per date.
I want to query the database, to know which days have data in them, at the
moment I load all the data for one month, and loop through it to see which
dates are in use - very inefficient of course.
How can I best query the database to know if a date is in use, without
extracting all the data at the same time?

I'm using Perl/mySQL
the current SQL is:

$sql="SELECT * FROM $database.$timetable WHERE Truckip like '$truckip' and
TIME<=$timeto AND TIME>=$timefrom order by TIME";

Where $timeto and $timefrom cover a 1 month segment.

Any ideas?

Richard.


--
For unsubscribe and other options, including
the Tip Harvester and archive of thelist go to:
http://lists.evolt.org Workers of the Web, evolt !




More information about the thelist mailing list