Can anyone please clarify what this query will return ?
SELECT TestCase FROM MyTable WHERE Verdict = 'PASS' AND
StartTime > DATE_SUB(NOW(), INTERVAL 2 MONTH)
Lets say I have a SP that has a SELECT statements as follows,
SELECT product_id, product_price FROM product
WHERE product_type IN ('AA','BB','CC');
But data goes to that IN clause must be through a single variable that contains the string of values. Something link below
SELECT product_id, product_price FROM product
WHERE product_type IN (input_variables);
But its not working that way. Any idea how to do this?
table1 has column CITY and COUNTRY. table2 has column CITY.
how do i delete from table2 all records that have CITY in common with table1 but also the COUNTRY='Russia' ??
please keep in mind that both tables have about 1 million rows of data
I've 2 tables - packages and items. Items table contains all items belonging to the packages along with location information. Like this:
Packages table
id, name, type(enum{general,special})
1, name1, general
2, name2, special
Items table
id, package_id, location
1, 1, America
2, 1, Africa
3, 1, Europe
4, 2, Europe
Question: I want to find all 'special' packages belonging to a location and if no special package is found then it should return 'general' packages belonging to same location.
So,
for 'Europe' : package 2 should be returned since it is special package (Though package 1 also belongs to Europe but not required since its a general package)
for 'America' : package 1 should be returned since there are no special packages
I've got 3 tables:
users (id, name, ...)
items (id, name, ...)
downloads (user_id, item_id, ...)
How do I get all users together with the number of downloads they have?
i have tables
profiles (id, name, deleted)
categories (id, name, deleted)
profiles_categories (id, profile_id, category_id, , deleted)
I have wrong query
SELECT p.id, p.name CONCAT_WS(', ', c.name) AS keywords_categories
FROM profiles p
LEFT JOIN profiles_categories pc ON p.id = pc.profile_id
LEFT JOIN categories c ON pc.id = c.id
WHERE p.deleted = FALSE
So, i want have result with all profiles with concan categories.name.
Thanks
I'd like to select all records from a table (names) where lastname is not unique. Preferrably I would like to delete all records that are duplicates.
How would this be done?
public ActionResult Example()
{
var q = from i in proba.name
select i;
return View();
}
How with this data make Json data and put them to table (on some View - no strongly typed)
I just wanted to develop a translation app in a Django projects which enables registered users with certain permissions to translate every single message it appears in latest version.
My question is, what character set should I use for database tables in this translation app? Looks like some european language characters cannot be stored in UTF-8?
I have a table like:
gold
gold_city | gold_type | gold_selltime
-------------------------------------
city1 | type 1 | 2012-01-01
city1 | type 1 | 2012-02-02
city1 | type 1 | 2012-03-03
city2 | type 2 | 2012-01-01
city2 | type 2 | 2012-02-02
city2 | type 2 | 2012-03-03
city3 | type 3 | 2012-01-01
city3 | type 3 | 2012-02-02
city3 | type 3 | 2012-03-03
How can I get 1 last result order by gold_selltime desc each group by gold_city and gold_type
I used this:
SELECT * , COUNT( * )
FROM gold_2012
GROUP BY gold_type , gold_city
ORDER BY gold_selltime DESC
but it did work.
I only have result like:
gold_city | gold_type | gold_selltime
-------------------------------------
city1 | type 1 | 2012-01-01
city2 | type 2 | 2012-01-01
city3 | type 3 | 2012-01-01
but I need it like:
gold_city | gold_type | gold_selltime
-------------------------------------
city1 | type 1 | 2012-03-03
city2 | type 2 | 2012-03-03
city3 | type 3 | 2012-03-03
I have set up my table with an index only on done_status(done_status =INT), when I use
EXPLAIN SELECT * FROM reminder WHERE done_status=2
i get this back
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE reminder ALL done_status NULL NULL NULL 5 Using where
but when I give this command
EXPLAIN SELECT * FROM reminder WHERE done_status=1
that's what I get back:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE reminder ref done_status done_status 4 const 2
first time it shows me it uses 5 rows second time 2 rows
I don't think the index works, if I understood it right first time it should give me 3 rows. What do I do wrong?
SHOW INDEX FROM reminder:
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
reminder 1 done_status 1 done_status A 5 NULL NULL BTREE
I have the following query....
UPDATE vehicle_catalog SET parent_id = 0 WHERE parent_id = SUBSTR(id, 0, 5)
I need to set all parent_ids to 0 where the first 5 characters of id is the same as the parent_id. This is effecting 0 rows when I'm looking at the data and it should be effecting over 10,000.
Any ideas on why this wouldn't be effecting all rows?
I have a table mytable( id, key, value). I realize that key is generating a lot of data redundancy since my key is a string. (my keys are really long, but repetititve) How do I build a separate table out that has (key, keyID) and then alternate my table to be mytable( id, keyID, value) and keyTable(keyID, key) ?
I have the following two table scenario:
users
id groups
1 1,2,3
2 2,3
3 1,3
4 3
and
groups
id
1
2
3
How do I return the IDs of all users that belong to group 2 and 1 for example? Should I look into join, a helper group_membership table or function to separate the comma delimited group IDs to get something like this:
group_membership
user_id group_id
1 1
1 2
1 3
2 2
2 3
... ...
We are looking for Web Designers & Developers. Urgent Opening.
Profile:-
a) Have exp. in Designing websites in wordpress
b) Have Creativity in work
c) Send us your work – [email protected]
d) Min Exp. required: 2 + years
e) Can Integrate the Facebook, Twitter & other social networking websites.
To review our profile – please check – www.dicorporation.com & www.ismoip.com
I want to select a stored value from database and then put it into a temporary variable.
For example, I have a column called category, one value under it is m, so I want to select this m value from the database, let's say from a table of a database called user_info.
Then I want to put it into a variable, let's name it $res.
After that, I want to do some condition stuff, such as if $res=="m",
Can anyone help me write a simple structure here?
Here is the code:
<?php
$sql = "Select category FROM user_info WHERE user_name = '"
.$_SESSION['username']."' and password = '".$_SESSION['password']."'";
$res = mysql_query($sql);
if($res == "a"){
include('MPIncomeStrategy.php');
}
if($res == "b"){
include('MPIncomeStrategy.php');
}
But it seems that the code is not able to detect $res =="category value in database". Did I just use the wrong way to store the category value?
I'm having difficulty creating a month-count select query in SQL.
Basically, I have a list of entries, all of which have a date associated with them. What I want the end result to be, is a list containing 12 rows (one for each month), and each row would contain the month number (1 for January, 2 for February, etc), and a count of how many entries had that month set as it's date. Something like this:
Month - Count
1 - 12
2 - 0
3 - 7
4 - 0
5 - 9
6 - 0
I can get an result containing months that have a count of higher than 0, but if the month contains no entries, the row isn't created. I get this result just by doing
SELECT Month(goalDate) as monthNumber, count(*) as monthCount
FROM goalsList
WHERE Year(goalDate) = 2012
GROUP BY Month(goalDate)
ORDER BY monthNumber
Thanks in advance for the help!
I'm working on a custom forum system and I'm trying to figure out how to put a thread on the top of the list if a user posts in it.
I've got this for my query
SELECT
user_threads.threadID,
user_threads.title,
user_threads.uid,
user_threads.postDate,
thread_messages.posted
FROM
user_threads,
thread_messages
WHERE
parent = :parent
GROUP BY
user_threads.title
ORDER BY
thread_messages.posted
DESC
Which doesn't appear to be working. if I post in a new thread, it remains where it is on the list.
I have this SQL by a programmer:
$sql = "
INSERT INTO
`{$database}`.`table`
(
`my_id`,
`xType`,
`subType`,
`recordID`,
`textarea`
)
VALUES
(
{$my_id},
?xType,
?subType,
{$recordID},
?areaText
) ";
My question is why is he using ? before values? How do I see what values are coming in? I did echo and it shows ?xType as ?xType. No values. What does ? stand for in SQL?
I have an inventory system, where a User has many inventory. We have a barcode column which needs to be sequential for each user. I run into a problem however when doing bulk association building. I end up getting several inventories for a user with the same barcode.
For example:
Inventory Table:
id | user_id | barcode
1 | 1 | 1
2 | 1 | 2
3 | 2 | 1
4 | 2 | 2
5 | 1 | 3
In the Inventory model I have
before_validation :assign_barcode, on: :create
def assign_barcode
self.barcode = (user.inventories.order(barcode: :desc).first.try(:barcode) || 0) + 1
end
It generally works, but ran into a problem when seeding my db:
(1..5).each do
user.inventories.build(...)
end
user.save
I end up with a bunch of inventories for user that have the same barcode. How can I ensure that inventories have unique barcodes even when adding inventories in bulk?
I'm using PDO's bindParam.
This is the function which checks every GET variable on the website. After changing it will echo it out:
function Check_Get_Param($val){
$value1=addslashes($val);
$string1=htmlspecialchars($value1);
$string2=strip_tags($string1);
$string3=intval($string2);
return $string3;
}
Hhere this will output the result:
Check_Get_Param($_GET['id']);
Now the idea is any id or id= any or id = %
$_GET['id'] = % will result 0 as % is not integer. How to allow % also?
How do I modify this function or any other function that I could filter the GET parameters so I could keep out the web from injections?
I am working on a basic messaging system. This is to get all the messages and to make the row of the table that has an unread message Green. In the table, there is a column called 'msgread'. this is set to '0' by default. Therefore it should make any row with the msgread = 0 - green. this is only working for the first row of the table with the code i have - i verified that it is always getting a 0 value, however it only works the first time through in the while statement ..
require('./connect.php');
$getmessages = "SELECT * FROM messages WHERE toperson = '" . $userid . "'";
echo $getmessages;
$messages = mysql_query($getmessages);
if(mysql_num_rows($messages) != 0) {
$table = "<table><tr><th>From</th><th>Subject</th><th>Message</th></tr>";
while($results = mysql_fetch_array($messages)) {
if(strlen($results[message]) < 30){
$message = $results[message];
}
else {
$message = substr($results[message], 0 ,30) . "...";
}
if($results[msgread] == 0){
$table .= "<tr style='background:#9CFFB6'>";
$table .= "<td>" . $results[from] . "</td><td>" . $results[subject] . "</td><td><a href='viewmessage.php?id=" . $results[message_id] ."'>" . $message . "</a></td></tr>";
}
else {
$table .= "<tr>";
$table .= "<td>" . $results[from] . "</td><td>" . $results[subject] . "</td><td><a href='viewmessage.php?id=" . $results[message_id] ."'>" . $message . "</a></td></tr>";
}
}
echo $table ."</table>";
}
else {
echo "No Messages Found";
}
There's all the code, including grabbing the info from the database. Thanks.