query

Retrieve the last 10 records from mysql database table, problem.

I have a weird problem. When I run this script I get 10 records from the database but they are all exactly the same. I have no idea what I am doing wrong or how to fix it. Please help me. I have tables AMCMS_highscores , AMCMS_users , AMCMS_games I want to look inside the AMCMS_highscores table, get the last 10 records but only where th...

Optimize SQL Query

Hi, I have following query on a MySQL DB: SELECT * , r.id, x.real_name AS u_real_name, u.real_name AS v_real_name, y.real_name AS v_real_name2 FROM url_urlaube r LEFT JOIN g_users u ON ( r.v_id = u.id ) LEFT JOIN g_users x ON ( r.u_id = x.id ) LEFT JOIN g_users y ON ( r.v_id2 = y.id ) WHERE ( ( FROM_UNIXTIME( 1283205600 ) >= r.from AN...

ORDER BY not working in MySQL 5.1

Hello, guys. I have a problem with sql query in php: select user, name, outlet, switch, port, vlan, mac, status from access where user like '%' and name like '%' and outlet like '%' and switch like '%' and port like '%' and vlan like '%' and mac like '%' and status like '%' order by 'user'; When r...

'Followers' and efficiency

I am designing an app that would involve users 'following' each other's activity, in the twitter sense, but I am not very experienced with database/query design/efficiency. Are there best practices for managing this, pitfalls to avoid, etc.? I gather this can create a very large load on the db if not done properly (or maybe even then?). ...

SQL : The influence of research speed with empty clolumns?

Hi, I'd like to know if some empty columns (with the field 'null' for example) can decrease the speed to make a query "SELECT" on a indexed column or a normal column. Thanks, Ba ...

select name of a person with at most grandchildren

Hi I have a simple table with persons, but there is a additional field witch holds information (person id) who is a father/mother of that person, so the 2 dimensional table can hold a familly tree the table is id first_name last_name salary spouse_id father_id mother_id sex 100 Steven King 26400 101 (null) (null) m 101 Neena Koc...

SQL Server Date Selection

Update How to write query on sql server to check case IsValidDate(Date) then Date+ ' days ' worked when IsEmptyorNUll(Date) then '*' ...

using different data connection in visual studio

It's possible to use 2 or more data connections in visual studio and using them in a single query, like we can do in sql server management (while we use mysql and mssql dbms same time): SELECT * INTO testMySQL.dbo.shoutbox FROM openquery(MYSQL, 'SELECT * FROM tigerdb.shoutbox')...etc ... etc... ...

What does the first argument to MySQL's Decimal function do?

Using MySQL 5.0.27 This query: SELECT CAST('543.21' AS DECIMAL(100,2)) returns 543.21 So does this one: SELECT CAST('543.21' AS DECIMAL(2,2)) In fact, I am having trouble figuring out what effect the parameter has. I am using it to aggregate numeric values in a varchar column (for legacy reasons!!) and round off to 2 decimal places. ...

how to take sqrt in sqlite

hi guys, This is the query of PHP using MySQL. can anyone please convert this query to sqlite query? Query: select SQRT(POW(latitude, 2) + POW(longitude, 2)) *110 as dist from route Best Regards, Thanks ...

Suggest me optimized query using 4 tables ( RIGHT JOIN v/s INNER JOIN & HAVING )

Hello ALL, I have following table structure table_country ==> country_id (PK) | country | status table_department ==> department_id (PK) | department | country_id (FK) table_province ==> province_id (PK) | province | department_id (FK) table_district ==> district_id (PK) | district | province_id (FK) NOTE: all tables engine are inn...

Query to find topics depending on the tag

Hi All, I want a search functionality in my application for the data like following topic_id tag 1 cricket 1 football 2 football 2 basketball 3 cricket 3 basketball 4 chess 4 basketball Now when i search for term cricket AND football o/p should be topic_id ...

SQL Compact 3.5 Ed, max length of SQL statement

Hi All, I'm developing a C++ application using OLEDB to communicate to SQL Server Compact Ed. 3.5. One feature of my application is a filter that helps the user narrow down data. Unfortunately, the selection criteria for the filter may become quite complex as the user may select data associated with various countries, keywords, categor...

Way to query database with SQLAlchemy where a date is a particular day of the week?

I have a table (called 'entry') which has a datetime column (called 'access_date'), and I want to do an SQLAlchemy query that only produces results where entry.access_date is a Monday (or any other day of the week specified by a number [0..6]). Is this possible? I am using sqlite & SQLalchemy 0.5.8 if that makes any difference. ...

SQLITE Selection and order by causing errors

Hi, i'm trying to get a query that returns rows only with a specified name, and sort descending by week (integer). Everytime I try and run it it gives me a FC and logcat says ERROR/AndroidRuntime(728): android.database.sqlite.SQLiteException: no such column: New: , while compiling: SELECT Name, Week, Total FROM notes WHERE Name=New OR...

php mysql sort by date (newest)

Right now im sorting by each articles auto_increment id with the query below mysql_query("SELECT * FROM articles ORDER BY id DESC"); I wanna know how to sort by a date field i made, that stores the current date via, strtotime() it should query the dates from newest to oldest. Current code $alist = mysql_query("SELECT * FROM artic...

CrystalReport and Stored Procedures using C# Question

Hello everyone, I have an application which needs to generate a report. However, I do not know how to generate a report using CrystalReport which is based on a query. Let's say I just need to generate report from my database which shows the values returned by my select query. I've never used Crystal Reports before so I'm new to this. ...

How do i optimize this query?

Hello, I have a very specific query. I tried lots of ways but i couldn't reach the performance i want. SELECT * FROM items WHERE user_id=1 AND (item_start < 20000 AND item_end > 30000) i created and index on user_id, item_start, item_end this didn't work and i dropped all indexes and create new indexes user_id, (item_sta...

MySQL server has gone away on simple select query

Hi, since any weeks I have a problem with a simple SQL Query where from time to time the mySQL Server has gone away. But in the last time I have this crashes every day 1,2 times day. The query is very simple: SELECT ... from table where field = 'some string' LIMIT 1 The table has 15 rows and the "field" where the query selects is a...

SQL: check to see which id's already exist

Let's say I have a list of IDs and I want to see if rows already exist with those IDs in my SQL database. Is there a single SQL command that I can issue to get back the subset of the ID list that's not already represented in the database? I could iterate over each ID in my code and issue a separate SQL check for each ID, but that sounds ...