mysql-query

Is this MySQL query a JOIN, a regular query or both?

I need to get data from 3 different tables. I know the basics about JOINs but when it comes to more complicated queries like getting data from 3 or more tables using JOIN I get a little confused and I just start playing with the queries writing what make sense to me, like the next one: SELECT movies.imdbID, movies.title, movies.year...

primary foreign key display in html table

ok here is it. i have two tables: products and warehouse product table consist of (pid(primary),pname,pcolor) while my warehouse table has (pid(primary foreign key=> products table), date_delivered,quantity). my question is can i display the warehouse table with pid,pname,pcolor,date_delivered and quantity since my primary ke...

How to count aggregates over a date in MySQL

I'm trying to do a cumulative aggregate in MySQL. My raw data looks like this: (my dates are month/day/year) user_id created_at source 1 1/1/01 foo 2 1/1/01 foo 3 1/2/01 bar 4 1/2/01 foo 5 1/3/01 foo .... Given this, I'd like to make a result t...

passing values using get from a dropdown populated from a mysql database

i have problem passing data from one page to another using GET, for example i have these: <form method=post action=edit.php> <td><input type=text name=firstname></td> <td> <? $query="SELECT * FROM gender; $result = mysql_query ($query); echo "<select name=gender_id>"; while($nt=mysql_fetch_array($result)) { echo...

mysql query + performance

is there a performance difference between $a = mysql_query("SELECT * FROM table WHERE id = 1 AND text = 'test'"); and $a = mysql_query("SELECT * FROM `table` WHERE `id` = '1' AND 'text' = 'test'"); ...

php + mysql_num_rows

is there a more efficient way of doing the following? $total_a = mysql_query("SELECT `id` FROM `table` WHERE `this` = 'that'"); $total_b = mysql_num_rows($total_a); if(!$total_b) { echo 'no results'; } else { $a = mysql_query("SELECT `id`, `time` FROM `table` WHERE `this` = 'that' ORDER BY `time` DESC"); while($b = mysql_fe...

MySql - order a query result in "some mode"

Hello. I have this data on a table : id name field 0 marco attack 1 andrea defense 2 luca medium 3 ernesto defense 4 vittorio medium 5 manuele attack i need to order as field. BUT, the priority list order (for my example) should be defense-medium-attack. so it must return : andrea, er...

7 Day Users Stat SQL Query

Can someone help me with a SQL Query that will display all users that have made a post every day for the last 7 days? My questions table is tblQA and my users are userID and questionID for the post. I want to run a query that helps me know how many active users are using the database every day. Thanks so much! ...

PHP: Is my method alright?

I'm making a "newest users" page. All users have an timestamp in the column "unixdate", that it stores when you register. Dont know if this is smart, but I like how effective the UNIX time() is and how simple it is. Now I am showing the newest users within 24 hours by doing this: $long = "86400"; // 24 hours in seconds $query = "SELEC...

PHP - need help with selecting rows from mySql

Hey, well Im trying to create an web index, every adveretiser in my database will be able to appear on a few categories, so i've added a "categorys" column, and in that column il store the categories seperated by "," so it will look like: 1,3,5 the problem is that i have no idea how im supposed to select all of the advertisers in a cer...

MySQL: Get dates with and without category/subcategory in ONE query (and sorted)

I have a database with 4 tables with this structure: categories subcategories dates events We have events, that can have multiple dates. Events are categorized in categories and subcategories, but can have only a category and no subcategory, too. I tried this query: SELECT t.id as sortid, t.numprint, s.titel, s.int...

asp - mysql not updating records

Dim prestaDB prestaDB = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=mysql50-64.wc1;PORT=3306;DATABASE=example_db;USER=example_user;PASSWORD=example_password;OPTION=3;" set conn = Server.CreateObject("ADODB.Connection") conn.open prestaDB conn.execute("update ps_product set quantity = " & sSeg(4) & " where reference = '%" & sSeg(0) &"%'")...

How to set and ending date value based on begining date with mySQL

I have a table with two fields, date_start & date_end, both are date fields. date_start currently is populated with various dates. I need to set date_end to 6/30 of the following year. So if date_start = 2009-03-15 then date_end = 2010-06-30 if date_start = 2010-03-15 then date_end = 2011-06-30 if date_start = 2010-07-01 then date_e...

How to make a variable LIMIT in a query, using MYSQL

I'm trying to build a query with a variable limit. As far as I know I cannot do something like select * from table limit my_variable;, but I've read on the internet about a workaround: SET SQL_SELECT_LIMIT = variable; I have to write this syntax before the query I want to apply the LIMIT in. This works fine if I write a SELECT query a...

Any Mysql guru who knows how to handle a custom group calculation scenario in 1 query?

I hope any sense can be made from my explanation. I was able to create the query, however my query only works for Items related to Containers, AND only if no more than one Items are related. I really hope anybody can be of any assistance! Consider the following objects: Container Person Item I have one table where instances of all o...

MySQL Add Data Based on Unique ID

Hi, I've been looking around for an answer to a MySQL Query question but have not been able to find an answer. Any help is appreciated... Ps. I'm a beginner. Issue: I have two tables, one is a main table with several columns and a unique ID column (sequential numbers) which is also the key. This table has had some rows of data deleted ...

MySQL query help needed to get clients who haven't bought anything in more than 180 days!

I have a table Orders which stores the info about orders(including OrdersName,OrdersSurname,OrdersEmail,OrdersPhone) which is the info I need to get. It contains a field OrdersFinishedTime which is a DateTime field which stores the data when the order was finished. What I need to do is select OrdersName,OrdersSurname,OrdersEmail,Orders...

MYSQL Find data in one table based on one of two fields in another table

Complete noob question, so apologies for that. I have two tables, a members table with an email address and telephone number in it and a second table that will have email addresses and telephone numbers in it with many instances of the members' telephone number or email address. I want to query the second table and list all results cor...

Mysql Covert rows to columns

I have a table with order numbers, first name, last name, question and answers. There are 5 questions asked to the user, each answer to a question generates 1 row of data, which produces 5 rows per user. I need a query that returns order number, first name, last name and the questions and answers converted to columns, returning 1 row per...

mySQL show database for user

Hi all, Anyone knows the mySQL syntax to show the database names that a specific user has the privilege to see in a mySQL database? Say the user is 'dimitris' accessing a database at 'localhost', what would be the syntax to see all databases he has the privilege to select, update, insert etc? Dimitris ...