mysql

sql statement help

Hello, I have a table which called people, and I have there 2 columns, name and age How can i select the names with age above 15 for example ? Thanks ...

MySQL "in" statement

This question is really just out of curiosity. Can someone shed some light onto why this query: insert into c ( select a.* from a,b where a.x=8 and y=1 and b.z=a.z and active > '2010-01-07 00:00:00' group by a.z ) is a million times faster (or close enough) than the query below whenever there's quite a few records involved...

Can anyone work out a more optimised SQL solution?

I am worried this is a bit expensive. Plus I will soon implement a normalized system for the tags so there will be additional joins. On top of that I have 4 tables (tbl_videos, tbl_articles, tbl_galleries and tbl_users) of which I want to display three results of each and thus will have to run the query four times on one press of 'se...

Setting one column value after another

I have a table where I want one value to be set to the same as another when inserting. Here's the table in question; CREATE TABLE categories ( id INT NOT NULL AUTO_INCREMENT, title VARCHAR(30) NOT NULL, root INT NULL DEFAULT id, PRIMARY KEY(id) ); I want the column ´root´ to get the same value as the ´id´ column gets when i...

Help with creating a reusable PHP function which will 'dynamically' call other functions

Hello! This is my first time I am trying to make something seriously with relational db in MySQL and some kind of CMS created in PHP with CodeIgniter. I came to the part where I have to insert some data in few many-to-many related tables. In my code everything works fine (well, with just few minutes of testing), but I need some help with...

SQL Query to get rows where values in a column do not exist in another table

I have a products table with a column that contains a space separated list of ids (like: "23 42 365"), the column is called "categories". The numbers refer to rows ids in another table (categories). I need to extract all product rows where all of the ids in the space separated list point to rows on the categories table that no longer ex...

Is it really worth it to normalize the "Toxi" way? ( 3NF )

I'm in the early stages of my database design so nothing is final yet, and I'm using the "TOXI" 3-table design for my threads which have optional tags, but I can't help but feel that the joining is not really necessary and perhaps I need to just rely on a simple tags column in my posts table where I can just store a varchar of something ...

Include admin role in users table from roles table

Is there a way to query users table like this: | id | username | ----------------- | 1 | user1 | | 2 | user2 | | 3 | user3 | and user_roles table: | id_user | id_role | --------------------- | 1 | 1 | | 1 | 2 | | 1 | 3 | | 2 | 2 | | 3 | 1 | assuming that role w...

MySQL grouping columns

is there any way i can group several of my columns together? in one for my scripts i need to set several of my columns to the same value, is there a better way than typing out all the column names in my update query? thanks ...

Where and how to store currency rates?

I have written a script that gets paypals current rates compared with the dollar every hour (the currency my products are in by default). The user can set their currency in their settings and that is store in the user table. My initial idea was to store all the currencies rates in the database and then when the user logs in store the c...

How to use HeidiSQL (or similar MySQL managers) with hosted databases

Hello! I'm using HeidiSQL ( http://www.heidisql.com/ ) to manage my databases at work (I prefer this over phpMyAdmin). Now, I want to use HeidiSQL with my personnal host plan, but when I connect to MySQL with my host, I connect with "localhost" in PHP but at work, I connect to databases with something like "supersqlserver.foo.net"... ...

How to test Empty string from database in django?

Hi, I'm having a hard time trying to test weather a record in the database exists for a perticular ID in django. something = User.objects.get(id=myID) if something is None: text="No Record" I need to do something like this. ...

Select by varchar column with IN() part in condition and int value returns all rows

Hello ! Can someone explain me why with that query: SELECT * FROM `tags` WHERE (tag IN ('willa-lentza', 2016)) it return me all rows from tags table, but when I put 2016 into quotes it works good ? tag column is varchar type. SAMPLE ENVIRONMENT CREATE TABLE `tags` ( `id` int(10) unsigned NOT NULL auto_increment, `tag` varchar...

Internet Explorer caching issue

Hi, I have a website that offers a service to subscribed members. It has been reported to me that one of the pages that has a form used to submit data to a mysql database has not been displaying saved changes. The form should display back data that has been stored in the database. (After the page has been submitted) I thought this was...

How can I programmatically connect to a remote database server that requires an SSH tunnel?

I'm working on an ETL using C# in which extracts data from a remote MySQL database that requires an SSH tunnel to connect. I currently have it working such that I first create my SSH tunnel manually using PuTTY and then programmaticly connect to the database normally using a MySqlConnection object, etc. How can I programmatically creat...

using mysql_close()

is it necessary to use mysql_close() at the end of a query in PHP? ...

How to run a programme from MySQL?

mysql > path_to_bin/name.exe Is there a solution? ...

PHP what happens when a string is double times mysqli_real_escape_string

I'm using mysqli. When I echo mysqli_real_escape_string($db,mysqli_real_escape_string($db,'"')); which one of those will be the output: 1. \" 2. \\\" ? Is there a safe way to check whether a string has been already escaped? Unfortunately, I cannot test at present as I cannot access MySQL for 24 hours. ...

Rows & cols SUM

Hello, i have a really complex query (mysql + php) and i would like to know the easiest way to sum columns and rows of a table apart from using SUM(x). Maybe a javascript could help. Thanks in advance. ...

Function to check if a string is backslashed for mysql

Since there is no function to check whether a string is escaped before entering it to the db, how can I do this with regex? $string = 'some" string'; if(!preg_match('//',$string)) { $string = mysqli_real_escape_string($string); } php manual: mysqli_real_escape_string backslashes characters encoded NUL (ASCII 0), \n, \r, \, ', ...