SQL & mdash; Counting with a nested subquery

I have a collection of tables in a relational database products categories orders line_items customers Products has a many-to-many relationship with categories (join table categories_products) and also has and belongs to many orders through line_item

Foreign key or composite key?

I just started applying everything that I read about table relationships but I'm kind of confused on how to insert data on tables with MANY-TO-MANY relationship considering there's a third table. Right now I have these tables. subject name code PK un

What's wrong with my NamedQuery

What is wrong with this NamedQuery? @NamedQuery(name = "Queries.findQueryIdsByRoleOfSameSid", query = "SELECT q "+ "FROM Queries q "+ "WHERE ((q.issueRole = :issueRole) AND "+ "(SELECT COUNT(*) FROM Queries qb

Sql query get all manager subordinates given name of manager

I have one query , I am not getting coorect answer. Please see to it carefully Employee data is stored in an Employee table with following columns: EmployeeId (Varchar) Name (Varchar) ManagerId (Varchar) ManagerId refers to the employee id of the Man

Find users who only have read permissions

I have a database table with three columns: The user, the filename and the permission (enumeration for "read","write","delete"). I don't get any further with the question: How to find all the user_ids which have ONLY the righ

How to add many-to-many relationships through a form?

My database holds the following data: fish --- id name cooking_type_id --- cooking_type --- id name --- cooking_type_relationships --- fish_id cooking_type_id --- I'm trying to create a form where you add a fish to the database. It all works fine, bu

Subquery / MySQL Query

I'm having a mental block with this query, I'm trying to return the max date and the maximum time and do an order by of the identity. It would be greatly appreciate if someone can add a pair of eyes to this type of query So : Data Set Identity, Date,

Bitwise SQL operation (MySQL)

So in my table i have id and bitwise columns like so +----+---------+ | id | bitwise | +----+---------+ | 1 | 1 | | 2 | 6 | | 4 | 60 | +----+---------+ From my c# code i'm setting these names to these binary values Name1 = 0x0001, Name2 = 0x0002, Nam

Get all WHERE cases in a query

I've got this query SELECT users.name FROM users LEFT JOIN weapon_stats ON users.id = weapon_stats.zp_id WHERE weapon_stats.weapon = 26 ORDER BY weapon_stats.kills DESC LIMIT 1; The problem it's that y need to get results changing where from 1 to 30,

mysql GROUP BY clause validation

Suppose I have a table with the following content: mysql> select * from test; +----+------+ | id | val | +----+------+ | 1 | 1 | | 2 | 1 | | 3 | 1 | | 4 | 1 | | 5 | 2 | | 6 | 2 | | 7 | 2 | | 8 | 2 | +----+------+ 8 rows in set (0.00 sec) mysql> Now

LOAD DATA INFILE with variables

I was tring to use the LOAD DATA INFILE as a sotred procedure but it seems it cannot be done. Then i tried the usual way of embedding the code to the application itself like so, conn = new MySqlConnection(connStr); conn.Open(); MySqlCommand cmd = new

Incremental primary key in the mySQL table with PHP

I'm attempting to use a form post to add rows to a mySQL table. Each row has a primary I'm calling quoteID. When a new form is submitted, it should add itself as a row in the table, with a quoteID of one greater than the previous quoteID. It current

Why my INSERT (MySQL) operation fails?

I have a table with the following structure: -------------- SHOW COLUMNS FROM versions -------------- +-----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+------

Simple PHP: mysql_num_rows

I have a simple question about mysql_num_rows(), If I were to have something like this: mysql_num_rows($getLatest['thread_id']) , would it work? Does mysql_num_rows() support the use of square brackets, like ['thread_id'] ?you need to pass the resour

Count from another table [mysql]

I have one table like this: +----+---------+-------------+ | id | site_id | search_term | +----+---------+-------------+ | 1 | 2 | apple | | 2 | 2 | banana | | 3 | 3 | cheese | | 4 | 1 | aubergine | +----+---------+-------------+ And another like thi

Persistent results of the MySQL query with PHP

Is there any way to persist the query results using PHP so you can use it another call to the web server? i know there is no way to persist a resource in php but looking for an alternative way to accomplish this: i have a reporting server and some qu

MySQL Creating an advanced query

Summary So I have 3 tables, which I have screenshots below. Every user will get 10 slides by default when they sign up, so that information is in the "slides" table. The template_id is just another table I have which is identical to the custom_s

SSIS: loss of SQL 2008 R2 data to MySQL

I have an SSIS package set up to export data from a SQL Server 2008 R2 table to a MySQL version of that table. The package executes however, I am getting about 1% of the rows failing to be exported. My source connection uses the SQL statement SELECT

Backend for autosuggest for fulltext search

I want to create an autosuggest for a fulltext search with AJAX, PHP & MySQL. I am looking for the right way to implement the backend. While the user is typing, the input field should give him suggests. Suggests should be generated from text entrys i

MySQL join where does not exist

I have a MySQL query that joins two tables Voters Households they join on voters.household_id and household.id Now what i need to do is to modify it where the voter table is joined to a third table called elimination, along voter.id and elimination.v