mysql

PHP - SQL: fetching results in round robin fashion

I have a table, which consists of 3 fields: id name status Every time I get the results, it should give me 5 names whose status = 1. Suppose the db contains following: id name status 1 A 1 2 B 1 3 C 0 4 D 1 5 E 0 6 F 0 7 H 1 8 I 1 9 J 1 10 K 1 11 L 1 12 M 0 1st time, fetch ...

mysql table join select

I have 2 tables: TOPICS (id, title) ANSWERS (id, id_topic, id_user, answer) ...and i want to do a select to detect all the questions belonging to a user in one select. I tried to do a join, but that doesn't work since if a user answered a topic twice, it will return 2 rows with the same topic. I tried to do a SELECT DISTINCT, but th...

SQL query find max row from the aggregated averages

Supposed I have the following tables: Sailor(sid, sname, age) Boat(bid, sid) Each boat can have many sailors, and each individual sailor can serve on many boats. What I want to do is to find the boat with the highest average age of sailors. I can find the average age of the sailor on each boat with this subquery: SELECT b.bid, A...

DB Design question: Tree (one table) vs. Two tables for tweets and retweets?

Hi I've heard that on stackoverflow questions and answers are stored in the same DB table. If you were to build a twitter like service that only would allow 1 level of commenting. ie 1 tweet and then comments/replies to that tweet but no re-comments or re-replies. would you use two tables for tweets and retweets? or just one table whe...

Merge duplicates into one row and sum up values using php

I have a table that hows the following rows... ID | TITLE | ARTIST | ADDED | HITS | HITS THIS WEEK -------------------------------------------------------------------------------- 7505 | Track 2 | Artist 1 | 2009-08-24 10:32:41 | 1539 | 2 7483 | Track 2 | Artist 1 | 2009-08-23 16:58:35 | 1450...

How to find the Birthday of FRIENDS Who are celebrating today using PHP and MYSQL

Hi all, How to find the Birthday of FRIENDS Who are celebrating today using PHP and MYSQL thanks in Advance... Fero ...

mysql Truncate table vs delete

We are about to deploy some code that truncates tables in our mysql 4 database. We are doing this to get around some replication 'weirdness' that we are seeing (and is widely known) with temp tables. My knee-jerk reaction when I saw this in a code review was "no", but I'm having trouble backing it up. So, the question is: am I just ov...

Can anyone tell me why my web server cannot connect to a DB server?

Hi everyone: "Can't connect to MYSQL server" error. The DB is a separate server. http://dpaste.com/99702/ I typed "nc dbserver 3306" and it returned: [XXXXXX] 3306 (mysql) : Connection refused Even in my GRANT options, I specified GRANT ALL TO . %... My friend said that the web server is being prevented from establishing a TCP connec...

I want to hide the details of record (of database) from user when date will be expired using php

Hi friends , I'm totally new to php & mysql, When I'm creating one trial application using php ,there is problem specify below, I want to hide the details of record (of database) from user when date will be expired using php , When one user logedin & create one record entry that time automatically current date is also entered in data...

Mysql transactions within transactions

In a PHP script working with a mysql database, I recently had the need to use a transaction at a point that happened to be inside another transaction. All my tests seem to indicate this is working out fine, but I can't find any documentation on this usage. I want to be sure - are transactions within transactions valid in mysql? If so,...

mysql trigger in different table

am using mysql 5.1..am wrote trigger after update.. CREATE TRIGGER myTrigger AFTER UPDATE ON employee FOR EACH ROW BEGIN INSERT into transaction_log values(12,'free'); END . . . here am using 2 tables..if update the data on employee table.value insert another table(transaction_log).but its not working.. ...

Store GMT time in mySQL table

Am looking for a way to store GMT timestamp in the table. Currently I use something like UNIX_TIMESTAMP(NOW()). But this will depend on which server my script is installed. In order to make it server-time agnostic, I want to store it in GMT time. I do not have any control over the server settings (like my.inf). Thank you for your time...

how to copy a column content from my local databse to main database??

i have same table at my local database and at my live-main database. I have to copy the content of a particular column from local to main not the whole table.How can i do that in mysql??? ...

Comparing two dates in mysql

Hi I have a mysql database table with a column called task_end_date and task_name. I want to select all the task_name from the table where the current date has passed task_end_date. How would i do that in mysql using an sql query. Thanks ...

collation conversion normal?

Hi, The following explain extended let me know that MySQL is internally doing a lot of collation conversion like latin1 and _utf8. (`mydb`.`node`.`status` = _latin1'1') and (`mydb`.`node`.`type` = _utf8'usernode') and (`mydb`.`node`.`uid` = `mydb`.`users`.`uid`) and (`mydb`.`usernode_list`.`uid` = _latin1'65484') Is it normal? Will ...

Convert Sub Query to a Join

Hi is it possible to convert this sub query to a join ? SELECT staff_no FROM doctor WHERE NOT EXISTS (SELECT * FROM patient WHERE staff_no = consultant_no); ...

How to get ALL rows starting from row x in MySQL

Hi all, In MySQL, how can I retrieve ALL rows in a table, starting from row X? For example, starting from row 6: LIMIT 5,0 This returns nothing, so I tried this: LIMIT 5,ALL Still no results (sql error). I'm not looking for pagination functionality, just retrieving all rows starting from a particular row. LIMIT 5,2000 seems like...

I want to import .xsl(ms excel) file in to myadmin (mysql db

hi, I'm totaly new for mysql, I have phpmyadmin(cs4 mysql) on which i have to import the excel file. plz help me,thanks in advance.I dont want to use command line. ...

Problem on how to display members info from a database with mysql and php?

Okay I have a piece of code that for some reason gives me the following errors. Warning: mysqli_query() expects at least 2 parameters, 1 given in Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in here is the code below. $dbc = mysqli_query("SELECT * FROM sitename WHERE id='$user_id'"); while($row =...

About MySQL index, multi-column or one column per index?

how do you create mysql index? multi-column or one column per index? what's your thinking? ...