sql

How to Find Missing Value Between Two Mysql Tables

select userid from cw_users where NOT EXISTS(Select userid from cw_users_data) The previous query won't do the job of course. Trying to find only a missing 'userid' from tableb by doing a comparison. Both tables contain 'userid' and there should be one similar on each. I'm trying to find which one is missing on second table. ...

sql joins and getting used to them

Hi, I had a big interview that I screwed up when the interviewer asked me to join three tables. I can verbally describe the different types of joins, but I froze up. I'm looking for something that gets me used to these types of problems so I can anticipate how to solve them. Anybody have any SQL excercises they could possibly recommen...

Supporting both Oracle and MySQL: how similar is their SQL syntax?

We use Oracle on a project and would like to also support MySQL. How close are their SQL dialects? Is it perhaps even possible to use the same SQL source for both without too many gymnastics? Details: We're using iBatis, a persistence manager that cleanly segregates the SQL statements into resource files. But we work at the SQL le...

SQL to LINQ generator

Hi; I am new to LINQ and just wanna know; is there any application in which I type standard SQL and it gives me its representing statement in linq? ...

Common table expression giving error

DECLARE @UDFLabel1 VARCHAR(50), @UDFLabel2 VARCHAR(50), @UDFLabel3 VARCHAR(50), @UDFLabel4 VARCHAR(50), @UDFLabel5 VARCHAR(50) SELECT @UDFLabel1 = UserDefinedFieldName01, @UDFLabel2 = UserDefinedFieldName02, @UDFLabel3 = UserDefinedFieldName03, @UDFLabel4 = UserDefinedFieldName04, ...

Permalink/slug best practices

I'm about to setup permalinks on a website and I'm wondering what sort of conventions I should follow in regards to generating them from the existing table of news articles. So far here are the rules/steps I've come up with: Create a dump file of my live database, set it up locally Add a new 'permalink' column to my news_articles tabl...

Aggregate functions - getting columns not included in the GROUP BY clause

I have a table which has three fields (item_id, source, and price). (item_id, source, and price) together make up the primary key. item_id source price ------- ------- ----- 1 paris 13 1 london 12 1 newyork 15 2 paris 22 2 london 15 2 newyork...

special characters wont be inserted into mysql table the right way...

I have a mysql database which Im trying to submit values to through a php file from a form. If I manually insert values to the table 'myTable' with special characters like the swedish åäö letters, it works fine. But when I am trying to use 'INSERT INTO' after a form is submitted on my page, to insert values to the table, all special ch...

Starting SQL Dev on Mac?

As I've never created an SQL database outside of University, I'd really like to get a bit of experience. At this moment in time I use a Mac and I've googled round but can't find any decent links. At the moment I have the mySQL Query Browser / Administrator, which I use for work when I bring my laptop in. However what additional softwa...

would it be faster to implement php code into html, or to use only php? See more details...

Im currently using PHP to fetch results from a mysql db. Im also displaying the results by building a table and all with PHP also. My question is, would it improve loading speed if I would just call the php variables from a HTML document (PHP + HTML). Or maybe it doesn't matter, and I should go with the ONLY PHP solution that I alread...

Why isn't psycopg2 executing any of my SQL functions? (IndexError: tuple index out of range)

I'll take the simplest of the SQL functions as an example: CREATE OR REPLACE FUNCTION skater_name_match(INTEGER,VARCHAR) RETURNS BOOL AS $$ SELECT $1 IN (SELECT skaters_skater.competitor_ptr_id FROM skaters_skater WHERE name||' '||surname ILIKE '%'||$2||'%' OR surname||' '||name ILIKE '%'||$2||'%'); $$ LANGUAGE SQL; If I ...

Combining data from different tables to form a news feed.

Let's say I have 2 tables, Message and Product. Whenever a user post a new products or messages, users who subscribe to that particular user will have their feed updated.It is similar to Facebook feed. The problem is how to combine the records from 2 different tables, Message and Product, to make a news feed, the feed has to be sorted b...

What is the equivalent of timestamp/rowversion (SQL Server) with PostgreSQL

Could someone help me find the equivalent of Timestamp/Rowversion (SQL Server) with PostgreSQL? I'm using NHibernate on Mono (UNIX). I think that Timestamp (PostgreSQL) is the equivalent of Datetime (SQL Server) - it's not what I'm looking for. Edit 1: For those who don't know what is a Timestamp/Rowversion in SQL Server: http://msdn...

JDBC proxy to simulate a SQL view?

I need to be able to execute (via JDBC) a straightforward SQL select query against a view (the view can be generated via a fairly complex source query). Here's the catch: I don't have write access to the database, so I can't create the view there. Is anyone aware of a JDBC proxy that will let you define a view against the underlying da...

many-to-many relationship INSERT question

i am trying to create a many to many relationship between 2 tables. ive got 3 tables for that. it follows TOXY model. table a: a.id (primary key) table ab: ab.a_id (foreign key) ab.b_id (foreign key) table b: b.id (primary key) how should i insert the data so it will be all linked up? like this? "INSERT INTO a ('name') VALUES ('my nam...

how to select n rows

i have a database about several companies which include their name, price of share, %age change: NAME PRICE % CHANGE ------------------------------------------------- a 67 11 b 23 6 c 456 5.89 d 112 ...

SQL question: How can I extract this information from these tables?

I have these 3 tables: EMPLOYEES Emp_id PK || First_Name || Last_Name || Hiring_Date Department Dep_Name || emp_id SALARIES salary || emp_id Two months ago, the company hired new employees. I need to write a SQL statement, that counts how many employees were hired. In the SAME statement, I need to find out, what are the finan...

Remove and split data into multiple columns in select statement.

I have data like following table I want to remove Titles ( Mr. Miss, Dr etc) from name and want to split data into First name and last name if two names exists. I want this in select statement. I can remove title using CASE statement but unable to split name into tow in same case statement. I want data like this but in select statem...

Ö (O with double dots) in Mysql record?

Hi, I have a row in a MySQL table with "ö". The whole word is "företag". How do I select that word in a sql query? I've tried with fretag but it didn't work. The table is using utf8. ...

wild expressions in mysql IN statement

i want to use a WILDCARD for everything in the statement beneath: "SELECT threads.* FROM thread_tag_map, threads, tags WHERE thread_tag_map.thread_id = threads.id AND thread_tag_map.tag_id = tags.id AND (tags.name IN ('WILDCARD'))"; What should I replace the WILDCARD with to be able to select every entry? I have tried...