I've got two tables (let's say "left" and "right" tables). The right table's got from none to several rows matching each row on the left table.
I need to perform a query where I can join the two tables the same way a LEFT OUTER JOIN works, but getting only one row for each existing one in the left table. That row should be the one corre...
I have a a table with a column groups INTEGER NULL. It has values
groups
5
7
<NULL>
If I do a select sum(groups) form table_name
I would get 12. How can I get null, when the column being summed has a null.
...
Hi all,
What does a multiple groups query actually accomplish? For example, if you have
SELECT * FROM table WHERE id = $id GROUP BY date, quantity, buyer;
What does that mean in plain English? I know what it means to "Group by date", but is "group by date, quantity" like a 2-d array?
Thanks.
...
I'm sorry, I don't know how to ask this question without giving you the whole story:
Consider the following tables:
**users**
ID | name
1 | Shawn
2 | John
3 | Josh
**groups**
groupName | userID
groupA | 1
groupA | 2
groupB | 1
This means that Shawn and John are part of group A, and Shawn is part of group B. Josh is part ...
Hi all,
I'm trying to SELECT entries of a certain type, name, EXCLUDING entries with the same name in a particular id. The last part is the tricky part that I can't get my head around.
SELECT name FROM table WHERE type = $type AND (name is not contained in an entry with id).
I want the result to be the set of all names that ARE...
Hi, I've seen in the code I'm working on, the following:
foreach( $mysql_result as $row ) $site_id = $row->id;
$mysql_result is, of course a mysql_result, so this foreach is equivalent to a while( mysql_fetch_row() )
Sometimes, the result is known to yield only one row, but the code still has a "foreach" so it gives the impression of ...
Summary:
I want to save two classes of the same name and different namespaces with the Fluent NHibernate Automapper
Context
I'm writing having to import a lot of different objects to database for testing. I'll eventually write mappers to a proper model.
I've been using code gen and Fluent NHibernate to take these DTOs and dump them s...
Hello, I am havin trouble with this code:
if ($_GET['offline']) {$extranet = $_GET['offline'];} else {$extranet = $online;}
$sql = mysqli_query($db,"UPDATE tbl_system SET value = '$extranet' WHERE property = 'extranet'");
echo $_GET['offline'];
echo $extranet;
echo $online;
In the database, the value of the field where the property =...
I have 2 rows of data in a mysql database. Both rows are identical with the exception of one column. What I am looking for is a query that will produce a single row with both distinct values. Can someone please help me out?
An example of the data is:
1 Administrator Test 2009-08-17 03:57:35
1 Miller Test 2009-0...
Hello, how would I count the number of sql queries executed on one page load?
I have a similar script to time taken for page to be generated, but not for how many queries have been executed.
You know what I mean, such as on SMF forums, in the footer, they have:
Page created in 0.136 seconds with 7 queries.
in the footer?
Replacing a...
Hi, i know that this is possible but i am confused as to how it works. I have been looking online for how it is done and I think i am missing something in the process
I have this jQuery code so far:
$("#Contact_Info").validate({
rules: {
username: {
required: true,
minlength: 6,
...
I am new to using prepared statements in mysql with php. I need some help creating a prepared statement to retrieve columns.
I need to get information from different columns. Currently for a test file, I use the completely unsecure SQL statement:
$qry = "SELECT * FROM mytable where userid='{$_GET['userid']}' AND category='{$_GET['cate...
I have 2 tables. 1 is music and 2 is listenTrack. listenTrack tracks the unique plays of each song. I am trying to get results for popular songs of the month. I'm getting my results but they are just taking too long. Below is my tables and query
430,000 rows
CREATE TABLE `listentrack` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`se...
What's the simplest (and hopefully not too slow) way to calculate the median with MySQL? I've used AVG(x) for finding the mean, but I'm having a hard time finding a simple way of calculating the median. For now, I'm returning all the rows to PHP, doing a sort, and then picking the middle row, but surely there must be some simple way of d...
A user fills out a form and if they choose to not fill out a field that is not required php does this:
if($_SESSION['numofchildren']=="")
$_SESSION['numofchildren']=null;
But when I use the session variable in a mysql query, the result is not null, but is 0. The column is a tinyint(4) that allows NULL.
Why am I getting...
Hey there guys and gals. I'm very new to php and am following various tutorials, reading books, watching videos etc.
The reason I'm learning is to create one specific web application, as well as to make that jump from simple geek to proper nerd, of course.
So far I've managed to learn most of what I need to create this web app.
The key ...
I asked this question before but still have not been able to get this working. Someone suggested a self join but I don't see where that will work. I am still getting 2 rows with the incorrect results. The self join is still present but I just can't seem to get the results I need.
I want to go from this:
id sender recipient
1...
I need to write the following query:
SELECT forum_threads.id AS id_thread,
forum_threads.topic,
forum_threads.date_created,
forum_posts.content,
CONCAT(users.first, ' ', users.last) AS author_name
FROM forum_threads,forum_posts,users
WHERE forum_threads.category_id=1
AND forum_threads.author_id=users.id
AND forum...
I'm trying to update a field where username = $username
UPDATE userinfo SET password = $newpass WHERE username = $username
However, I'm getting the error "#1054 - Unknown column 'bob' in 'where clause'" when I replace $username with bob.
Any idea how to correctly write this?
...
I have a complex form which uses blur events to trigger updating to mysql. There is validation which disables the submit button until all required fields are completed. The problem is, users are managing to submit the form even though they haven't completed all the fields.
My theory is, for some reason the database is ignoring some of ...