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




Retrieve Count


I have these 3 tables
Code:

forumstopicsposts
idforumidtopicid

As you can see posts does not have the forumid. What I want to do is calculate

1. No. of topics per forum
2. No. of posts per forum




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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?

#1136 - Column Count Doesn't Match Value Count At Row 1
I'm getting the above error with the following SQL Statement. I cannot seem to find the error in the code. The select statement does pull multiple rows.

I'm using my SQL version: 4.1.19

Any clue on why this isn't working?

INSERT INTO `Grants` ( `Project_Code` , `Grant_Code` , `Fiscal_Year` , `Capital` )
VALUES (
(
SELECT Project_Code, Grant_Code, FY, SUM( Capital )
FROM Grants_Temp
WHERE Project_Code = 'OSUT'
AND FY = '2006'
AND Claim_Month = '072006'
GROUP BY Grant_Code
ORDER BY Grant_Code
)
)

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).

Retrieve Images
I was wondering if is it possible for me to store images in mysql n den retrieve it out to thru the sql Select statement?
If so how wld i go abt writing mysql Statement?? Pls can anyone guide me here im rather new in it.

Retrieve Postings
so I stopped using varchar for my date field and have thus started to use the date fieldtype. So, how can I go about retrieving items posted within the last 5 days?

Field (posting_date) is set up as 2006-22-04, so I want to display items from 4/17/06 - 4/22/06.

Retrieve Foreign Keys
OK, so I've got a few innodb tables with references sorted out for foreign keys. Such as...

Table 1
id (PK)
...
...

Table 2
id (PK)
table1_id (FK)
...
...

Table 3
id (PK)
table1_id (FK)
table2_id (FK)
...

Now, I want to build a dynamic query for Table 3 using the foreign keys to figure out what other tables to reference based on the foreign keys.

But, from what I can see I can only get the foreign key info from a "SHOW CREATE TABLE" or "SHOW TABLE STATUS" type query. This means I have to do a bit of fiddly string manipulation to get the FK info.

Have I missed something?

EDIT: Sorry, I just realisd I posted this in the Databases forum instead of the MySQL forum /:[

How Do I Retrieve Only The First N-characters From A Field?
Is there a built in function in MySQL that will allow me to retrieve a fixed number of characters from a varchar field. I want to be able to use it sort of like this:

SELECT DISTINCT mySqlFunction_to_return_N_chars(`importantField`, #chars_to_retrieve)
FROM mytbl

How To Retrieve Table Comment?
With creating a table you can give an additional comment. Which query will retrieve this comment?

Map Friends And Retrieve The Photos They Can See
I am planning to implement a social network in php. it will have nothing but friends and photos. So, a user can have friends and each photo is marked private or public. those marked private can be viewed by friends only.

So, say user X is not a friend of user Y, I need to first check if he is a friend. Then, retrieve the list of photos for Y and check each photo if it is private or public.

Any basic info on what would be the optimal way to implement this ?

Currently I have a users table, a photos table and a user_friend table. I do simple select and inner joins to retrieve what I need. Is there a better way to retrieve what each user is allowed to see on the other user's profile page ?

Retrieve MySQL Data
Until recently I ran a php/apache mySQL wbsite on MacOSX. For some
reason I can't get the machine working again so now the site is
offline. I succeeded to copy the MySQL data from the Mac OX partition.
However, this is the 'raw' data - not a SQLdump but the frm, myd and
myi files for each table.

The data is not of much use if I want to use it in a website again,
I'd rather have a SQLdump.

So now my question is:

Can I just add these files in the data directory of another mySQL
installation I setup locally under win2k and be able to make a dql
dump?

How To Retrieve Latest Date
I have a table that looks something like this:

table prop1 {
id;
addr;
zip;
name;
} (it's much larger than this)

And another table that looks like

table prop2 {
id;
price;
date;
}

The first table will have one entry per address. The second can have any number of entries with varying prices and dates. I need to retrieve the highest price with the latest date from prop2 for each entry in prop1.

I have tried this code:
select (p.id, p.addr, pp.id, pp.price, pp.date, MAX(pp.price) from prop1 p, prop2 pp where p.id = pp.id group by p.id order by p.addr);

This sort of does what I want. But it lists all of the results. So if one address has ten entries, all ten entries are returned. If I add a LIMIT 1, that works for the first address but no others are returned.

Is there a way to return just one entry for each address and have that entry be the one with the highest price and most recent date (or even just the highest price if need be)?

How Do I Retrieve A Mysql Password
I am updating a website for a client but they have lost the MySQL password, I have the username, how do I retrieve the password?

How To Retrieve Data By Row Number?
How can I write the clause to get records on specific row?

for example:
table ABC has:
firstname1 lastname1
firstname2 lastname2
firstname3 lastname3

Now I want to get the second line by sql statement.

Select * from ABC where ROWNUM=2?

How To Retrieve Turkish Characters?
I am developing a small website with php+mysql. my PHP version is 5.0.5 and MySQL version is 4.1.11 I am working on Windows XP Pro.

I have some data in my MySQL table and my data contains some turkish characters, like "ö, ç, ğ, ı..." when I write a query using appropriate turkish characters, I get an empty result set. eg:

SELECT * FROM my_table WHERE column1='ağırlık'
//This returns nothing!

But, if I change my query like below, it comes up with some data, however it again doesn't display the turkish characters eg:

SELECT * FROM my_table WHERE column1='agirlik'
//OUTPUT
//column1
//-------------
//a??rl?k

Note for curious ones: my table contains a record where column1='ağırlık'...

How can I make my first query work and get "ağırlık" instead of "a??rl?k" as the output?

Retrieve From Hierarchical Data
i have a table like this.

id parentid c3...
-------------------
0 0
1 0
2 0
3 1
4 1
5 2
6 2
7 2
8 5
9 5
10 5
11 3
12 7

i want ids that has a id as parent or grand-parent or grand-grand-parent, so on.

----------------------------2
-----------------------5--- 6--- 7
---------------------8 9 10-----12

Suppose if i want subids of 2 then it should return 2,5,6,7,8,9,10,12.

How To Retrieve The Data From Mysql?
I'm using php to embed mysql code, on each page I want to show all information for the same dept: SELECT * FROM $table where DEPT='$dept' LIMIT 1

Now I want to have two links (previous, next) which points its previous/next available record(on same DEPT).

I want to know how I can search for the next record on same DEPT and have OFFSET added to the statement?

Retrieve List Of Users
I'd like to know a way to know which users had a birthday in last 7 days...

Example, I've this:

Name - Born
John - 1963-12-24
Lisa - 1979-11-23
Peter - 1981-08-01

Then, script should return "Peter, 1981-08-01"

The php script will be execd through cron once a week, and no matter which day it is executed, it must give the same result.

Retrieve Top 100 Selling Products
I have table of categories, and a list of products with a counter in the product table.  The counter in the product table gets incremented by 1 each time that product is sold.  How do I get the top 100 selling products in each category.

Better Retrieve User Object
This question must be asked a lot, but I still couldn't find anything good. I have a lot of php pages that need to use the user object. What I am wondering is what would be a better way to handle this:

1. Make a global user object once logged in, and re-retrieve it only when it is updated, or
2. Create a new local user object for every page if logged in, and go from there.

Obviously the first one will make less queries to the database, but I am still wondering how others handle this. Maybe there's another option.

Retrieve Lowest SUM Values
why this statement produces an SQL error around the MIN function?

Code:

SELECT hotels.id, sr.id, MIN(SELECT SUM(srr.price) FROM searchresultrooms srr WHERE srr.searchresult=sr.id)) AS theMin FROM hotels JOIN searchresults sr ON sr.hotel=hotels.id WHERE sr.search=169321 ORDER BY theMin.

Retrieve MySQL Entry &
does anyone know a way how to do the following:
Use PHP maybe to retrieve a database entry from MySQL (Song Name) and set MSN Messenger's Personal Message (Or Display Name) to the Song Name?

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 Root Password
I have a dedicated server with 1&1 (really bad tech support) and they don't seem to want to give me the root user password. The server is running Fedora Core 2 - is there anyway I can retrieve the root password? I want to be able to set CRON jobs to do MySQL dumps for backups every now and then.

RETRIEVE FIELD NAMES
What MySQL command would I use if I wanted it to return to me the
names of every field in one of the database's tables?

Retrieve Field Names
What permissions are needed to get the field names from Mysql? Just SELECT?
I have some code that stopped working and the only thing that I can think of that might be the cause is the permissions (I got all restrictive thinking I was being smart).

The user has SELECT, INSERT, UPDATE, DELETE only

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?

INSERT Data And RETRIEVE
I realize this is a simple question. I tried to search through the forums but am not sure how to word the question to get any results. My search queries returned no matches from the forums...
If you can answer my question that would be great. Even better would be a suggestion on how to search this forum so that the answer turns up.

this is the SQL so far:

INSERT INTO image_object SET image_name='11185131276164.jpg', image_float='left', image_caption='Caption', image_alt='Alt Text';

What i need is for MySQL to return a result telling me the auto_increment id that was given to the record at the time of the insertion.

Retrieve Results Starting With Number
if I want to retrieve records starting with the letter A, I could do "WHERE field LIKE 'a%'"

But what would I do to retrieve all results starting with anything *but* letters?

Retrieve Smallest Record From Mysql
I have the following in a mysql DB


ID Name Money
1 Kevin 20000
2 John 1000


is there a mysql query i can run that will Select the name of the person where money is the smallest value?

Query To Retrieve This Week's Birthdays
I have a Members table in my database in which I collect the date of birth for each member. I have been trying to write a MySQL query to retrieve the birthday's for this week from the Members.DateOfBirth field, which is of type datetime.

I have been able to successfully retrieve Member's birthdays for this month using the following query, but can't figure out how to take the query to the "this week" level.

Does anyone know how I could do this?

Here is the query I am using now to retrieve birthdays for this month:

Retrieve Data From 2 Tables In 1 Query
I've got 2 tables content & sections I need to:

SELECT id, title, section_id , status FROM content

and now I'd like to get title from sections WHERE id = section_id from the first part of the query.

I've tried with unions but doesn't seem to like it..

Retrieve Record Number Of Insert
I am using ASP/VBscript.

How can I retrieve the record number of a record I have just inserted without doing something ugly like max(ID)?

Thanks in advance for suggestions. Steve Davis
hey.you AT HaHaHa.com.au
http://www.HaHaHa.com.au/weblog

Me? I can't even spell ASP!

NOTE: This sig does not include any reference to voting, stars, or marking posts as helpful as doing so is cause for membership termination

Store And Retrieve Milisecond Data
it is possible to store AND retrieve subsecond (milisecond) data? As far as I understand, you can't retrieve msec from a TIMESTAMP or DATETIME type.

Retrieve Result + Colum Names
How can I get the column names related to the data coming from this query?

$result = mysql_query("SELECT * FROM my_table WHERE reg_id = 5");

// ???

$data = array('field_name_1' => "field_contents_1",
'field_name_2' => "field_contents_2", ...);

Retrieve Information Using Date Field?
I have a table called Event. In the table I have a date field. I want to Select specific fields and retrive events from the begining of this month to the end of february. In other words, 3 months span.

This is what I have,

SELECT EventDate, EventID, EventTitle, Event, DeptCode
FROM Events
WHERE DeptCode == '2'
ORDER BY EventDate ASC

Now my question is how do I ask for events in 3 monts span.

Retrieve The 'month' From Datatype Date
is there any function that allows me to retrieve a particular information, say, the month, from the datatype 'date'?

How To Retrieve SHOW Results From MySQL Using ADO
How to retrieve the result of: SHOW [FULL] COLUMNS FROM tbl_name

using ADO, from ASP. (what are the recordset fields, or what else?) how to retrieve the result of a SELECT, from ASP, using a connection object and a recordset object.

RETRIEVE FIELD NAMES From A TABLE
What MySQL command would I use if I wanted it to return to me the
names of every field in one of the database's tables?

Retrieve Values From Db And Assign Vars To Them
The following query is my umpteenth attempt. I am trying to bring four values out of my Db and assign a variable name to each.


unless ($Customer_ID || $User_Name || $PassWord) {} else {
$dbh->do("SELECT FROM $table (Customer_ID, User_Name, PassWord, Client_Full_Details) values ('$StoredCustomer_ID', '$StoredUserName', '$StoredPassWord', '$StoredClient_Full_Details')");

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'

Column Count Doesn't Match Value Count At Row 1
I am getting the following error when I run my query.
Column count doesn't match value count at row 1

I have looked up this error and have checked and I appear to have the right number and names in my query. In the DB table I have 34 columns, and that is what I have in the query.

The last 4 in the query are for the names of the images being uploaded, but am not sure how this all works, so I don't know if I need them, but have them there until I know for sure. Comment, Purchase and Remarks are not used in this form, but I have added them so everything is being shown in the query. Code:

Retrieve Data Posted In Past 3 Months Only... How?
can i know how to retrieve data that posted in past 3 months only so other posting with more than 3 months will not be displayed...

eg.

PHP

select * from post_table where post_date<=(past 3 months)

Retrieve List Of Column Names From A Table
Can anyone tell me the function that retrieves a list of column names from a table? Sorry to bother with a small request but I'm having difficulty finding this.


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