data:
id bb
1 14,35
2 5,11,12,125,36
3 3,23,45,15,1
4 651
5 5,1,6
6 1,7
For example, i wan't get id which with value '1'. So id(3,5,6) should return , but not others with '14' or '11'.
DB: Mysql
...
I'm trying to do a select statement and it works except that it's not limiting the number of results for each user (U.id) to 5.
SELECT F.id,F.created,U.username,U.fullname,U.id,I.id,I.cached_image
FROM favorites AS F
INNER JOIN users AS U
ON F.faver_profile_id = U.id
INNER JOIN items AS I
ON F.notice_id = I.id
WHERE faver_profile_...
I've looked around and the only questions/answers I can find on the site are related to sorting by the ID in MySQL. Questions such as: stackoverflow.com/questions/645102 and stackoverflow.com/questions/169233
I am instead looking to find the previous and next rows when sorting by another column other than ID. For example:
I first run t...
The cms I'm currently working with only supports live editing of data (news, events, blogs, files, etc), and I've been asked to build a system that supports drafting (with moderation) + revision history system. The cms i'm using was developed in house so I'll probably have to code it from scratch.
At every save of a item it would create...
Hi,
I need to make a stored procedure or function that returns a set of rows. I've noted that in a stored procedure i can SELECT * FROM table with success. If i fetch rows in a loop and SELECT something, something_other FROM table once per loop execution, I only get one single result.
What I need to do is looping, doing some calculation...
Mysql:
Table_A
------------
id name
1 Name1
2 Name2
Table_B
------------
a_id type value
1 width 100
1 height 100
1 color red
2 width 50
2 height 80
It's unknown how many type values exist in Table_B.
how to get result as:
id name width height color
1 Name1 100 100 red
2 Name2 50 80 null
...
Hello,
I have this query which works correctly in MySQL. More background on it here.
SELECT c.*, SUM(ABS(v.vote)) AS score
FROM categories c,items i, votes v
WHERE c.id = i.category_id
AND i.id = v.voteable_id
AND v.created_at > '#{1.week.ago}'
GROUP BY c.id
ORDER BY score DESC LIMIT 8;
I tried running it in Postgresql and it ...
Hi, I asked this question before, but not very well! Basically I have an editing page for a CMS, somewhere along the line (from the element onwards) the fields display in the box next to where they should be displaying. any ideas why?
<?php
if(isset($_GET['id']))
{
$query = "SELECT * ".
"FROM studies ".
"...
Right, another question on queries (there must be a syntax guide more helpful than mySQL's manual, surely?)
I have this query (from another helpful answer on SO)...
SELECT DATE_FORMAT(`when`, '%e_%c_%Y')date, COUNT(`ip`) AddressCount FROM `Metrics` WHERE `ID` = '1' GROUP BY DATE(`when`)
I now want to do a similar query to get unique/...
I'm using PHP and MySQL. I need to do a query:
DELETE FROM db1.players WHERE acc NOT IN (SELECT id FROM db2.accounts)
The problem is, that db1 and db2 are located on different servers. What is the fastest solution for such problem?
To be precise: I'm using 2 connections, so I think I can't use one query for it.
...
Hi guys,
I have a problem with a really slow connection between my Java code and a MySQL Database. I don't know where the bottle neck is.
My program is more or less a chatbot. The user types something in, my program splits the sentence into words and sends it word per word to the database. If it finds something there, the user gets an ...
mysql table slalry:
aid year slalry
1 2000 1000
2 2001 2000
3 2002 3000
4 2003 4000
h
ow to get result as :
aid year slalry
1 2000 1000
2 2001 3000
3 2002 6000
4 2003 10000
...
I have a database of users and a database of cards. The users see the cards repeatedly.
I kept a record of every time the users saw the cards and how long they looked at the card.
Now that I've got that data, I want to analyze it by considering the first time that each user looked at each card.
I got a list of the average msToAnswer ...
Hi, I'm trying to insert multiple rows into a MySQL table depending on the number of options selected from a multiple select box. currently it is inserting one row (regardless of how many options are selected) but the 'strategyname' column is empty each time.
Any ideas on how to insert multiple rows and why the values of the options ar...
I am developing an Erlang application which requires a LOT of DB writes. My schema has, in addition to the primary key, another attribute with a unique constraint enforced.
Say I have an ID, an unique_constraint_field, and some other fields. I need to now update a row in the DB corresponding to the unique ID, given that no other row sh...
What would be the easiest way to count the new records that are inserted into a database? Is it possible to include a count query in with the load query?
Or is something more complex needed, such as recording the existing last record and counting everything added after it?
edit:
I have a cron job, that uses LOAD DATA INFILE in a scrip...
This SQL query disgusts me. I didn't write it, but it's a massive cause of issues on our servers. I'm willing to split it up into multiple queries and do some of the processing via PHP (like, the RAND()).
$sql = "SELECT a.code, a.ad_id, a.position, a.type, a.image, a.url, a.height, a.width
FROM " . AD_TABLE ." a, " . USER_GROUP_TABLE ...
Hi,
I have the following MySQL timestamp:
2009-06-23 16:21:48
How can I convert it to a format like mktime()?
...
I am building Django +MySQL on dreamhost, but met the error messages:
Caught an exception while rendering: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ORDER BY tag.used_count DESC, tag.name ASC' at line 1")
I traced hard and found the ...
I found this awesome code online to help with pagination, and it's working well, the only problem is: each page displays the same 4 rows.
Any ideas will be much appreciated
<?php
//Include the PS_Pagination class
include('includes/ps_pagination.php');
//Connect to mysql db
$conn = mysql_connect("localho...