List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:September 4 2001 9:09pm
Subject:Re: sql command question
View as plain text  
>currently, to list the last 100 records in a table I use this sql command:
>
>select * from test order by T desc  limit 100;
>Note: "T" is the name of a field in my table "test" .
>
>can I instead use record number or use the count function to get the 
>same result?

MySQL doesn't really have the concept of "record number".

>I don't have an index field in my table and the table has no primary 
>key for a good reason.

I don't know what the good reason is, but that's also preventing you from
doing what you want.

>
>Also, is this command possible?
>
>select count(*) from table1, table2;
>if it is,  why can't I get the correct result:
>
>table1 has 337 records and table2 has 23860 records but the result 
>is 8040820 instead.

That's the correct result.  You're running a full join on the two tables,
which produces each combination of rows from the tables.  337 times 23680
is 8040820.

Do you mean the sum of the counts of the records in each table?

SELECT @n1 := COUNT(*) FROM table1;
SELECT @n2 := COUNT(*) FROM table2;
SELECT @n1 + @n2;



>
>
>thanks
>--------------------
>Nissim Lugasy
>216-433-2708
>lugasy@stripped
>--------------------


-- 
Paul DuBois, paul@stripped
Thread
sql command questionNissim Lugasy4 Sep
  • Re: sql command questionPaul DuBois4 Sep