Hi,
is it possible to use date_sub like this ?
$dt = date("Y-m-d h:i:s");
$query = "INSERT INTO `table` (`date`) VALUES ('DATE_SUB('$dt', INTERVAL 15 DAY)')";
$result = MYSQL_QUERY($query);
Thanks
Hi
I have asked this question before in this forum and they told me that it will retun an empty result set,I want to know that if I set the column with null values it will retun an empty result set?also the ANSI_NULLS is OFF ,thanks
SELECT 'A' FROM T WHERE A = NULL;
What does the below query explain?
SELECT * FROM `jos_menu` WHERE (id = 69 OR id = 72)
I know its very silly question, but sometimes easy things creates mess in my skulls interpreter.. Pls help
EDIT
Its giving me record for both IDs, why is it doing so? It should five me the record for either 69 or 72....
i have two tables
table1 fields
fid,fname,fage
a ,abc ,20
b ,bcv ,21
c ,cyx ,19
table2 fields
rcno,fid,status
1 ,a ,ok
2 ,c ,ok
3 ,a ,ok
4 ,b ,ok
5 ,a ,ok
i want to display rectors like this
fid from table1 , count(recno) from table 2 and fage from table1
fid,count(recno),fage
a ,3 ,20
b ,2 ,21
c ,1 ,19
i try many sql queries but got error
Thanks
Hi all,
I don't have phpMyAdmin installed in my web site.
Sometimes I was doing some select SQL command at the backend,
but when I typed in this command to show all records from table Users:
select * from Users;
The records were printed as ???? | ??? ??? ??? |.
I don't want to make any permanent changes to the charset in the database,
so, how is it possible to temporarily displayed a few records as utf8 when needed?
i am doing:
explain select * from calibration;
it says 521332 rows
when i do:
select count(*) from calibration;
i am getting 521961
can someone explain whats going on here?
So, I have three tables with the following rows: Customers (Customer_id and Name), Orders (Customer_id, Product_id, Quantity) and Products (Price).
How do I write a query which shows all customers who spent more than 1000$? Do I have to join the tables?
I am trying to build a query that does a sum if a certain parameter is
set. For example:
SELECT SUM(IF(<condition>,field,field)) AS total_value
...which is working correctly.
But i have more than one condition in IF(), like:
SELECT SUM(IF(<condition> <condition>,field,field)) AS total_value
..which is not working, could you have any idea what should be the right query for this.
while($row=mysql_fetch_array($result))
{
$output .= "<Reports>";
$output .= "<ProjectName>";
$output .= $row['ProjectName'];
$output .= "</ProjectName>";
$output .= "<ProjectCount>";
$output .= $row=mysql_fetch_array($result)
$output .= "</ProjectCount>";
$output .= "</Reports>";
}
Can i return the number of rows in table like this, i am getting XML markup error.
Hi,
I need to perform a simple update query where the update should only be done, if there is no value with updating value (item_name). For example,
DB table [item_types]
item_id(PK) | item_name
Assuming there exist item_id with 6, My attempt is
UPDATE item_types as k SET k.item_name = 'item_1' WHERE NOT EXISTS (SELECT * FROM item_types as a WHERE a.item_name = 'item_1') AND k.item_id = '6'
But this gives me error
"You can't specify target table 'k' for update in FROM clause"
Could you please explain the error here and how can I achieve this ?
Thank you
Can anyone please clarify what this query will return ?
SELECT TestCase FROM MyTable WHERE Verdict = 'PASS' AND
StartTime > DATE_SUB(NOW(), INTERVAL 2 MONTH)
I am having trouble figuring our how I can get results only when products.published, product_types.published, and product_cats.published = 1 but my query isn't working. Please help:
SELECT
`products`.`title`,
`products`.`menu_id`,
`products`.`short_description`,
`products`.`datasheet_icon`,
`products`.`datasheet`,
`products`.`ordering`,
`products`.`product_type_id`,
CASE WHEN CHAR_LENGTH(`products`.`alias`)
THEN CONCAT_WS(':', `products`.`id`, `products`.`alias`)
ELSE `products`.`id`
END AS slug
FROM
`products`,
`product_cats`,
`product_types`
WHERE
`products`.published=1 AND
`product_cats`.published=1 AND
`product_types`.published=1 AND
`products`.`product_cat_id`='42' AND
`product_types`.`id` IN (1,40,48,49,50)
GROUP BY `products`.`id`
ORDER BY `product_types`.`ordering`, `products`.`ordering`
A table in my database has a column, DATE_ADDED (stored in seconds). I want to extract all rows with the most recent date (aka largest value for DATE_ADDED).
The only solution I have come up with is to SELECT all the rows in ASC (ascending) order, grab the last entry from the table, check the date on this, and perform another SELECT on the table but this time only for the discovered DATE_ADDED.
Is it possibly to simplify this series of queries into a single one? My thought is I should be able to do a SELECT on all of the largest values in the table, but I am struggling to come up with a proper query.
i need to show the number of online visitors, but there is a problem with selecting algoritm to do it!
maybe i must create a table in DB, where i'll store ip addresses of visitors and time of visit! by so i can show the count of ip addresses, which's time = NOW() - 10 minutes, for example...("now()-10 minutes" is just to show the logic, i know that this is not a function:)
is this goog way to go? or maybe it's better to use AJAX methods to store the data?
please give me an idea.
Thanks
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
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 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?
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'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?
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