Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Subtracting from another table?

Author  Topic 

Slim-jim
Starting Member

1 Post

Posted - 2011-04-16 : 13:38:57
Hi all,
I hope I've posted this in the correct section.

Can someone help me solve this problem I have, I need to subtract the count(test_topic_id)from another table.
The other table being called USER_TABLE & the subtraction from "user_posts" of the same user_id.

Im not a noob at databases Im a nooooooooooooob and dont know how to do this, heres the code I have in use.

Thanks in advance
Jim


define('TIME', 24); // 24 hours 
define('YOUR_ALLOWED', 5); // 5 a day

$sql = 'SELECT count(test_topic_id) as test_count
FROM ' . TEST_TABLE . '
WHERE test_time > ' . (time() - 3600 * TIME) . '
AND test_poster_id = ' . $user->data['user_id'];
$row = $db->sql_fetchrow($db->sql_query($sql));
if ($row['test_count'] >= YOUR_ALLOWED)
{
return true; // Daily Limit. We've made all we're allowed.
}
}

return false; // We haven't hit our limit. ! No limits on me! hehe

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-04-16 : 21:12:23
This does not look like T-SQL. This forum is for Microsoft SQL Server. If you are looking for help on a different DBMS, you may get better responses in a forum specific to that DBMS, or in a general forum such as dbforums.com
Go to Top of Page

jcelko
Esteemed SQL Purist

547 Posts

Posted - 2011-04-16 : 21:45:36
Please post real DDL. Learn to use ISO-11179 rules for the data element names, avoid needless dialect and use ISO-8601 temporal formats, codes and so forth. People cannot read your mind, so post your code and clear specs if you really want help.

What you did post was not SQL.

--CELKO--
Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Go to Top of Page
   

- Advertisement -