mysql-query

Finding Domain Names from List of URL using MySQL/JAVA/PHP

Hi Friends http://en.wordpress.com/tag/1000-things-we-hate/ http://en.wordpress.com/tag/1019/ http://en.wordpress.com/tag/1030-am/ http://www.yahoo.com/index.html http://www.msn.com/index.html i am having list of domains as above in my DB, i need to get only domain name from this, how can i do that in mysql or in JAVA or in PHP ?? ...

MySQL Select rows where timestamp column between now and 10 minutes ago

I have a timestamp column that auto updates on insert/update. I want to get the rows that have been updated within the last 10 minutes. SELECT * FROM status WHERE code='myCode' AND 'stamp_updated' BETWEEN NOW() AND DATE_ADD(NOW() , INTERVAL - 10 MINUTE) ORDER BY stamp_updated DESC LIMIT ...

How to get difference between 2 columns

I have a query that is producing something like this: StartTimestamp | EndTimestamp ================================ 100 | 450 -------------------------------- 150 | 500 I'd like the result to also include the difference between EndTimestamp and StartTimestamp: StartTimestamp | EndTimestamp | Difference ...

Subsequent queries depends on result of initial query: how to?

Say I have 3 queries. Query 1 returns a piece of information that Query 2 and Query 3 needs. Is there a way for Query 2 and Query 3 to access this piece of information from the result of Query 1? Right now, I have Query 1 executing twice: once in Query 2 and once in Query 3. This doesn't seem efficient to me. Is there a better way in M...

How to sort within a group of data and sort the groups by max value within each group in a MySQL query.

I have a dataset that looks like so: id entry_id the_data 1 100 Z 2 300 B 3 100 C 4 200 F 5 300 Q 6 300 A 7 300 L 8 100 N 9 200 O The results should give only the 3 most recent records (by id) for each corresponding entry ( by entry_id...

Conditional of a loop within a loop is not matching

I have two databases, each containing email addresses of users. I've written a script that has the sole purpose of seeing which email addresses exist in both databases. With that being said, please look at the following loops. Each loop contains hundreds of records (I've printed out the results from each as a verification). However,...

Setting a Value by assuming column in a Table MySQL/PHP

Hey i am having a table with 8 column and following values 1 2 3 4 5 6 7 8 0 1 0 0 0 0 0 0 i need a query which will analyze the no of 1's and 0s in the column and if no of 0 is greater than 4 then it should print failed else pass,how can i do that? either by MYSQL or PHP? ...

mysql_fetch_row(): supplied argument is not a valid MySQL result resource in

Hi, I am getting the error (mysql_fetch_row(): supplied argument is not a valid MySQL result resource in) for this query. Why? <?php set_time_limit(0); //MySQL globals $mysql_server = "***";//change this server for your Drupal installations $mysql_user = "***";//Ideally, should be root $mysql_pass = "***";//Corresponding password $con...

SQL many to many select

category_product --------------- id_category id_product product --------------- id_product id_manufacturer manufacturer --------------- id_manufacturer name How would I create an SQL query so that it selects all the names from manufacturer when id_category is equal to something? ...

What is the shortest way to get the next free id from MySQL table ?

I have a table with id column. ids are in ascending order but not necessarily consecutive. For example: 1, 2, 3, 5, 6, 10, 11, 12 I need to find the next "free" id, i.e. max(id) + 1 (or 1 if the table is empty). Currently I'm doing this in PHP like this: function get_free_id($con) { $sql = "SELECT MAX(id) AS last_id FROM Table"; ...

MySQL query help: how to pivot this table?

Given a table like this: ============================================== | ID1 | ID2 | ID3 | Name | Value | ============================================== | 16 | 1 | 100 | item_name | Toys | | 16 | 2 | 101 | item_name | Computer | | 16 | 1 | 102 | item_price | 55 | | 16 | 2 | 103 | item_price ...

Change the result of mysql_query

Can I modify the result that I have received from mysql_query than reset the pointer with mysql_data_seek($result, 0) and process the output like from normal query Dummy example: $result = mysql_query($query); while($row = mysql_fetch_array($result)){ $row[$fieldName] = $this->someFunction($row['id']); } mysql_data_seek($result, 0);...

STR_TO_DATE does not exist

Hi, if is use this command in mysq: SELECT node.nid AS nid, users.uid AS users_uid, node.created AS node_created FROM dr_wiwe_node node LEFT JOIN dr_wiwe_content_type_classified node_data_field_classified_valid_till ON node.vid = node_data_field_classified_valid_till.vid INNER JOIN dr_wiwe_users users ON node.uid = users.uid WHERE ( ( ...

Codeigniter active record with several like or?

Hey.. I've run into a problem using several "like" in my sql-query (generated with Codeigniter's activerecord): SELECT * FROM (`posts`) WHERE `city` LIKE '%test%' AND `title` LIKE '%%' OR `text` LIKE '%%' Thing is, it appears to read this query as if there was a parenthesis around the first like and the second like, but I want there t...

Conditional Columns - MySQL query

I need to display a particular column in my SQL result only if it is not null. If it is null, I don't want that column to appear at all in my result. Is there a way to express this condition in SQL? ...

MySQL query joining table data

This is eluding me. I am trying to pull meta data about players that I have matched against each other in a game. Eg: Player 22 vs. Player 54 I have 2 mysql tables. Table: players (id, name, image_url, etc) 1 | John | john.jpg | etc 2 | George | george.jpg | etc 3 | Ian | ian.jpg | etc 4 | Steve | steve.jpg | etc Table: matchups (i...

Getting Root & Leaf Nodes for a Given Id - How to?

Assume I have a table that has the following structure: ================= | Id | ParentId | ================= | 1 | 0 | | 2 | 1 | | 3 | 1 | | 4 | 2 | | 5 | 2 | | 6 | 3 | | 7 | 3 | ----------------- This results in a tree like this: 1 / \ 2 3 / \ / \ 4 5 6 7...

cannot replace contents of atable using load data local infile...

hi every one.. load data local infile 'input.txt' replace into table t fields terminated by '|'; doesn't seem to replace the former contents, its creating duplicate copies of the entries, i tried with 'ignore' also,but even it is not working..pls tel me where i'm going wrong.. i created d table using... create table t (name varchar(2...

MySQL Query: Long time spent in 'init' state

I'm performing an update on a MySQL table (myisam engine) that, according to the profiler, is spending an inordinate amount of time in the 'init' state: mysql> show profile for query 2; +----------------------+-----------+ | Status | Duration | +----------------------+-----------+ | starting | 0.000057 | | ch...

Need help with PHP and MySQL

I have a table which has a column with numbers (no specific order). What would be the shortest way to insert the minimal number in this column into $min variable in PHP ? ...