All Questions

3765
votes
33answers
1969888 views

What is the difference between "INNER JOIN" and "OUTER JOIN"?

Also how do LEFT JOIN, RIGHT JOIN and FULL JOIN fit in?
429
votes
37answers
731379 views

How do I split a string so I can access item x?

Using SQL Server, how do I split a string so I can access item x? Take a string "Hello John Smith". How can I split the string by space and access the item at index 1 which should return "John"?
479
votes
33answers
492358 views

Fetch the row which has the Max value for a column

Table: UserId, Value, Date. I want to get the UserId, Value for the max(Date) for each UserId. That is, the Value for each UserId that has the latest date. Is there a way to do this simply in SQL?...
69
votes
13answers
29534 views

What is SQL injection?

Possible Duplicates: How does the SQL injection from the "Bobby Tables" XKCD comic work? https://stackoverflow.com/search?q=sql+injection Can someone explain SQL injection? How ...
240
votes
2answers
512126 views

Efficiently convert rows to columns in sql server

I'm looking for an efficient way to convert rows to columns in SQL server, I heard that PIVOT is not very fast, and I need to deal with lot of records. This is my example: -----------------------...
430
votes
13answers
403111 views

How to do a FULL OUTER JOIN in MySQL?

I want to do a Full Outer Join in MySQL. Is this possible? Is a Full Outer Join supported by MySQL?
261
votes
13answers
234731 views

Using LIMIT within GROUP BY to get N results per group?

The following query: SELECT year, id, rate FROM h WHERE year BETWEEN 2000 AND 2009 AND id IN (SELECT rid FROM table2) GROUP BY id, year ORDER BY id, rate DESC yields: year id rate 2006 p01 ...
48
votes
1answers
62764 views

MySQL pivot row into dynamic number of columns

Lets say I have three different MySQL tables: Table products: id | name 1 Product A 2 Product B Table partners: id | name 1 Partner A 2 Partner B Table sales: partners_id | produ...
707
votes
10answers
469647 views

INNER JOIN ON vs WHERE clause

For simplicity, assume all relevant fields are NOT NULL. You can do: SELECT table1.this, table2.that, table2.somethingelse FROM table1, table2 WHERE table1.foreignkey = table2.primarykey...
304
votes
11answers
123261 views

Explicit vs implicit SQL joins

Is there any efficiency difference in an explicit vs implicit inner join? For example: SELECT * FROM table a INNER JOIN table b ON a.id = b.id; vs. SELECT a.*, b.* FROM table a, table b WHERE a.id...

Previous Next