if (select * from table where x=1) returns 0 rows then i need (select * from table where x=2 [or some other query]). is it possible to do this in a single MYSQL query with a conditional statement?
edit: all answers with 'UNION' work but only if both queries selects from the same table (or tables with the same number of columns). What if...
Hello,
I am using a MySQL table called "login" with the structure below. The code beneath the table structure uses data pulled from the table "login."
For certain loginids that were created about two months ago, the code echoes out the variable "website" fine, no problem. For loginids that I have created recently, the code does not...
If I define a MySQL index over two fields, how do I find out, which two belong together (using MySQL commands).
Here is an example table:
mysql> DESCRIBE lansuite_wiki_versions;
+-----------+-----------------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default...
Hi all, i have a string field (and i can't change this because the date format) on mysql database that contains a date (Like: "01-03-2010"), and i wan't to make a function to compare that date and return true if today's date is newer than 8 days, and false if the date is lower or bigger than today's date...
Example:
01-03-2010 < (08-06...
So, i'm having a lot of trouble with this little piece of code. An example timestamp is this: '1278509422000'.. the problem is that it comes in as a string and I have to convert it somehow. I know about the problem with milliseconds and have tried dividing by a 1000 and much more (intval/floatval) but it just will not become a correct da...
Example:
SELECT `film_id`,COUNT(film_id) AS COUNT FROM films_genres AS FilmsGenre
WHERE genre_id In (4)
GROUP BY film_id,COUNT
HAVING COUNT = 1
return:
film_id | COUNT
7 1
6 1
But I want it to return:
film_id
7
6
How do I return only 1 colomn?
...
if an user login in his/her home page then he needs to see his friennds, i hane one table name
frienddetails containing userid and friendid,and another table name profile containg userid,name.now how can i show user's friend in the home page? the friend details need to show in user home page,but that is in the table named profile.
...
I am refactoring some code. I have a PHP page that contains a MySQL query and stores the result in a PHP variable $my_result. This result is then echoed to a Flash SWF during embedding with SWFObject.
I now want to call this PHP page that makes the query from a javascript function like so - one change I have made to the PHP is that ins...
if an user login in his/her account then he will see all of his friends profile picture in his home page as like orkut, i have these tables
fsb_friendlist containing: friendlist_memberid and friendlist_friendid
fsb_profile containg: profile_userid, profile_name, profile_image, etc
now how can i show user's friend in the home page?
...
Hi folks,
I am trying to make connections to my database using connection pooling library: DBPool. Here's my source code.
DBUtils.java
/**
*
*/
package DB;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.sql.ConnectionPoolDataSource;
import snaq.db.ConnectionPool;
import c...
I'm working on a Rails web application with a MySQL database. I'm using migrations to modify the schema. I've just run into a problem wherein I'm getting an invalid record error on inserting a new record. The relevant tables:
users
id | name | email | ...
academic_records
id | scholar_id | gpa | ...
academic_records.scholar_id is a ...
Whilst writing working my way through a list of scripts I need to write I started using the MySQLdb package. This all worked fine in my Terminal by doing a simple python at the command line then import MySQLdb. However after about 30 minutes I figured I better move this to Eclipse incase I start making some stupid mistakes... Eclipse for...
As in title.
I'm considering to use separate tables with JOIN or use single table, basically I'm worried about the performance.
Thank you.
...
i am using php and running sql queries on a mysql server.
in order to prevent sql injections, i am using mysql_real_escape_string.
i am also using (int) for numbers casting, in the following manner:
$desired_age = 12;
$query = "select id from users where (age > ".(int)$desired_age.")";
$result = mysql_query($query);
that work.
But,...
How to grant on multiple databases? MySQL.
Something like
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE
ON 'databasesprefix%'.*
TO testuser@localhost IDENTIFIED BY 'testpasswd';
...
Hi guys..
I am trying to search MySQL database with a search key entered by the user. My data contain upper case and lower case. My question is how to make my search function not case sensitive. ex:data in mysql is BOOK but if the user enters book in search input. The result is not found....Thanks..
My search code
$searchKey=$_POS...
I have a datamodel, let's say: invoices (m:n) invoice_items
and currently I store the invoice total, calculated in PHP by totalling invoice_items, in a column in invoices. I don't like storing derived data as it paves the way for errors later.
How can I create a logical column in the invoices table in MySql? Is this something I would be...
I am using MySQL and PHP, and I want to find the difference between two dates.
I have a table named advertisers, which has a field web_start_date. I want to select all entries where the web_start_date is less than 30 days from the current date
...
I know there is this question that is very similar, but I wanted to add my specific situation and see if the answer is different.
I've read that you can simply do ORDER BY RAND() but that that is a bad idea for large tables. However, I can limit my rows to a max of about 160 with the WHERE clause. So the question is, is the WHERE clause...
Hey everyone,
Im looking to delete information in two different tables in 1 query, based on an ID.
I've tried several solutions on here to accomplish this task but still have not accomplished what I'm trying to do.
Table 1 - Content
---------- ---------
ContentID | Content
--------------------
Table 2 - Votes
--------------------...