sql

MySQL: Select distict field, but get the rest of the columns as well?

I want to select distinct product_series, but I want all the other columns too. This is my query as it stands: SELECT DISTINCT product_series FROM cart_product WHERE product_brand = "everlon" AND product_type = "ring" AND product_available = "yes" But this only gives me product_series, but I need all the other columns in that row...

Mysql - How do I order results by alternating (1,2,3, 1, 2, 3, 1, 2, 3,) rows, is it possible?

I want to order my results by client 1, 2, 3, then again client 1, 2, 3, and so on. Is there a way to do this without using a for loop or making three separate queries? Not only that, but I am working with paginated data so it needs to return x results, but consistently. Any ideas? GROUP BY maybe? client_id project_id project_name ...

Foreign Key reference in mysql innodb

Simply put: I have a table with 2 columns: one is username and other is nickname. I have another table where I have 2 columns: one is username and other is countNicknames. I want countNicknames to contain the number of nicknames each user has (and whenever I insert a new nickname to the table1, the value under table2.countNicknames will...

Add total to group.

I have a Order Details table. What I want to do is create 1 query to show OrderNumber | SKU | QTY | Price | Line Total | 1 SKU1 1 10.00 10.00 1 ---- 0 0.00 10.00 2 SKU1 2 10.00 20.00 2 SKU2 3 1.50 4.50 2 ---- 0 0.00 ...

Why won't this simple SQL statement work?

dateposted is a MySQL TIMESTAMP column: SELECT * FROM posts WHERE dateposted > NOW() - 604800 ...*SHOULD*, if I am not mistaken, return rows where dateposted was in the last week. But it returns only posts less than roughly one day old. I was under the impression that TIMESTAMP used seconds? IE: 7 * 3600 * 24 = 604800 ...

Best to use * when calling a lot of fields in mysql?

I know generally it is always better performance to build mysql queries to name every item you need but for example on a profile page I might need every item except a few. SELECT user_name,f_name,l_name,country,usa_state,other_state,zip_code,city,gender,birth_date,date_created,date_last_visit, user_role,photo_url,user_status,frie...

ORA:00900 Invalid sql statement

i created a procedure with 32 in argument,it sucessfully created.but when i am executing this in back end oracle the errror came ORA:00900 Invalid sql statement ...

sql problem,challenge

I want to get id a b c -------------------- 1 1 100 90 6 2 50 100 ...from: id a b c -------------------- 1 1 100 90 2 1 300 50 3 1 200 20 4 2 200 30 5 2 300 70 6 2 50 100 It's the row with the smallest b group by a. How to do it with sql? EDIT I...

why to use BETWEEN operator while we can do without it.

As seen in below two queries we find that they both work well ,Then I am confused why should we ever use between because I have found that between behaves differently in different databases as found in w3school SELECT * FROM emplyees WHERE salary between 5000 AND 15000; SELECT * FROM emplyees WHERE salary >= 5000 AND salary <= 15000; ...

Accessing binary data from SQL reporting services

Hi, ive had some experience working with SQL server and reporting services for standard data types however i am now trying to develop a report that contains binary data. Example - i have a table with approximately 5 fields and the last field is a binary data field that contains a pdf inside it. I want to have a report that shows the fi...

specify what columns not to insert values into mysql table

I have a stored procedure that inserts a row into a table with an autoincremented column. It gives me a warning but succeeds if i simply put "" for the value of the autoincremented column. The way I get rid of the error currently is to specify which columns the insert values are for... "insert into app_table(app_id,name,...) values(...)"...

Friendship System Sql Structure & Query

Hello. I am coding a friendship system and it has two tables. members id username password friends id user_id friend_id status Let's say that i want a query that can select the friends IDs of the member $userId how possible to make this in one query? I found a solution which is to make 2 queries. The fist selects the friends W...

Low MySQL Table Cache Hit Rate

I've been working on optimizing my site and databases, and I have been using mysqltuner.pl to help with this. I've gotten just about everything correct, except for the table cache hit rate, no matter how high I raise it in my.cnf, I am still hitting about 0% (284 open / 79k opened). My problem is that I don't really understand exactly ...

Join 2 Tables and display everything

I have 2 simple tables: table a: id | txt ---+---- 0 | aaa 1 | bbb 2 | ccc table b: id | tel ---+---- 0 | 000 2 | 111 I am trying to join 2 tables like this: SELECT a.*,b.* FROM a,b WHERE a.id=b.id It works, but, if there is no entry in the "b" table it wont show anything. what the sql shows is something like this: ...

sql statement to retrieve a list of results (from other table) for a given record?

I have the following schema: TABLE bands -> band_id -> property1 -> property2 -> ... TABLE tracks -> band_id -> track_id The tracks table typically maps a single band_id onto multiple track_ids (there are multiple tracks for each band). My goal is to build, for the bands that match certain conditions (in terms of property1, property...

MySQL, DELETE Query with a Join

Can someone help me understand what's wrong with this query: DELETE FROM noteproject INNER JOIN note ON noteproject.noteID = note.noteID INNER JOIN person ON note.personID = person.personID WHERE noteID = '#attributes.noteID#' AND personID = '#attributes.personID#' ...

Importance of varchar length in MySQL table

I have a MySQL table where rows are inserted dynamically. Because I can not be certain of the length of strings and do not want them cut off, I make them varchar(200) which is generally much bigger than I need. Is there a big performance hit in giving a varchar field much more length than necessary? ...

How can I get more intuitive feels about django relationships(like:Many-to-one,Many-to-many )

i use xampp(it has mysql) I was Confused on this django relationships, who can give me a code example(or text) to let me feel it intuitive .thanks (like:Einstein described the theory of relativity) ...

Adding fields to optimize MySQL queries

I have a MySQL table with 3 fields: Location Variable Value I frequently use the following query: SELECT * FROM Table WHERE Location = '$Location' AND Variable = '$Variable' ORDER BY Location, Variable I have over a million rows in my table and queries are somewhat slow. Would it increase query speed if I added a...

Conversion failed when converting datetime from character string

when i compile the following code , "Conversion failed when converting datetime from character string" exception raises , what is wrong with that ? code : DateTime after3Dyas = DateTime.Now.AddDays(3); try { Con.Open(); SqlCommand Command = Con.CreateCommand(); Command.CommandText = ...