mysql-query

MySQL complex JOIN problem - Unable to achieve proper results

I have two table: Vehicles(Id, VIN) and Images(Id, VehicleId, Name, Default). I need to select the vehicles VIN and its default picture to display in a table. The problem I am having is that if a default picture is not set I still would like to select an image to display if it exists. If no images exist the vehicle information obvious...

MySQL complex query not yielding proper results

I have two table: Vehicles(Id, VIN) and Images(Id, VehicleId, Name, Default). I need to select the vehicles VIN and its default picture to display in a table. The problem I am having is that if a default picture is not set I still would like to select an image to display if it exists. If no images exist the vehicle information obvious...

sql complex tree rows

i have following function with a query. it works fine with integer id, but if the id is varchar (ID: Xewi3adc), then it dont work. well i dont know how to make it work yet, i been making lots of modifications, but i could'nt get it work. DROP FUNCTION IF EXISTS album_tree_connect; DELIMITER $$ CREATE FUNCTION album_tree_connect(value...

SQL Query for count of records matching day in a date range?

I have a table with records that look like this: CREATE TABLE sample ( ix int unsigned auto_increment primary key, start_active datetime, last_active datetime ); I need to know how many records were active on each of the last 30 days. The days should also be sorted incrementing so they are returned oldest to newest. I'm using ...

Order by date in mysql

I want to sort my result form mysql by date. I use the query like this: <?php $date = $db->get_query("select distinct created_date from comments"); $condate = ''; for($i=0; $i < count($date); $i++) { $condate = $date[$i]['created_date']; $data = $db->get_query("select id,created_date from comments where created_date='$condate' order...

UPDATE table SET related_id=NULL WHERE related_id doesn't exist in related table.

I need to update table and set table.related_id (column that "binds" the table with related table) to NULL where the table.related_id doesn't exist in the related_table as related_table.id. example: TABLE: ---------------------- id | name | related_id ---------------------- 1 | aaa | 15 2 | bbb | 36 3 | ccc | 7 4 | xxx | 43 RE...

Is this possible to achieve directly from mySQL? mySQL - SQL Dilemma

Hi guys, I wonder if it would be possible to query two tables as pictured bellow, and achieve the following result. The two tables are (note that the page_id in the pages_contents table corresponds to the id column in the pages table.): Wanted result (the two tables are joined by the biggest version number): Thanks in advance for...

Use the result of one Mysql command in Another Mysql Command??

Excuse my ignorance but I'm having a tough time figuring this out. I'm trying to take the result from one mysql command, and use it in another command. Here's my code, it doesnt work. //select the event end date of event ID $sql = "SELECT enddate FROM mm_eventlist_dates WHERE id = $id"; $result = mysql_query($sql); //plug in the eve...

Can MYSQL queries dramaticly slow my website ?

Hey, I'm doing a website that requires me to use about 5 mysql "SELECT * FROM" queries on each site and I'd like to know if it can slow the download speed in any way. ...

How to find out all the commands executed on a MySQL database within a given timeframe?

Is it possible to find out all the command executed against a database in a given timeframe? For example, I would like to know who executed insert command on a database table in the last 24 hours. Any help would be greatly appreciated. Thanks. ...

How does a MYSQL Self-Join Work?

I recently asked a question about Self-Joins and I got a great answer. The query is meant to find the ID, Start Date, and Price of Event2, Following Event1 by 1 Day. The code WORKS fine. But I don't understand HOW. Could someone explain as thoroughly as you can- what the different parts of the query are and what they do? SELECT even...

What is wrong with this index definition in this MySQL query?

CREATE TABLE `pastebin` ( `pid` int(11) NOT NULL auto_increment, `poster` varchar(16) default NULL, `posted` datetime default NULL, `code` text, `parent_pid` int(11) default '0', `format` varchar(16) default NULL, `codefmt` mediumtext, `codecss` text, `domain` varchar(255) default '',...

Are unique indexes better for column search performance? (PGSQL & MySQL)

I am curious as to whether CREATE INDEX idx ON tbl (columns); vs. CREATE UNIQUE INDEX idx ON tbl (columns); has a significant algorithmic performance benefit in PostgreSQL or MySQL implementations when scanning the indexed column(s), or whether the UNIQUE keyword simply introduces a unique constraint alongside the index. I imagin...

How to set query parameters in MySQL Query Browser?

Can the MySQL Query Browser set parameters of a parameterized query? If so, how? I tried populating the Parameter Browser tab but it doesn't seem to actually set parameters when I execute the query. I searched for quite a while in Google (e.g. mySQL Query Browser parameterized) but had no luck finding the answer. I found this threa...

How to join results from two tables in one output file?

I have two tables in MySQL DB; table1, table2. Both of them have a single column (float) values. It's actually a dump from our research project which produces a single value result. And many of these values get repeated and sorting and filtering them in Python would be cumbersome, so I though perhaps dumping them in a table in DB woul...

find likewise data from two tables in mysql

i have two tables in my database one is A other one is B A is having few fields in which three are id,name,group B is having feilds like id,title,description, etc. i have to search the id's of title and description that are having data similar to table A's name or group and then have to insert the id's in a field of table A. For exampl...

MYSQL insert random from list.

I would like to add a random value to a table. While I know how to add random integers within a range, I am currently stumped on how to add a randomly selected item from a list. Let's say I have a MYSQL table for IM accounts. I would like to fill it with random data. INSERT INTO `im` (`im`, `service`) SELECT LOWER(`last`), RANDOM-SELEC...

How can I get this mysqli database class working?

I'll cut right to the chase. All I can achieve at this point with this class is a database connection. I am unable to make a query. Can you show me exactly how to get this working and/or show me how to recode it in a better way. <?php class database{ public $dbHost = ''; public $dbUser = ''; public $dbPass = ''; public $dbName = ''; p...

How can I replicate "SHOW TABLES" in Hibernate?

I'm trying to iterate over all of my tables so I can truncate each one (at the beginning of each of my JBehave tests). I thought I would be able to: List<String> allTables = session.createSQLQuery("SHOW TABLES").list(); But hibernate throws a SQLGrammarException, complaining that "Column 'TABLE_NAME' not found." I guess this is beca...

MySQL - Different UPDATE else INSERT statement

I am busy doing an UPDATE/INSERT request, but here is the crux: table PLAYERS { player_id game_id team_id position number } What is supposed to happen is the following: I test if there is an entry where player_id = '$player_id' AND game_id = '$game_id' AND team_id = '$team_id'. If there is, then the following ha...