Documento
select c.nombre as nombrecli, s.nombre as nombresec, p.id as id,
p.ano as ano, f.nombre as nombre, p.subtitulo as subtitulo
from (((proyectos as p inner join ciudad as f on p.id_ciudad = f.id)
inner join clientes as c on p.id_clientes = c.id)
inner join sectores as s on p.id_sectores = s.id)where p.id_iso639='ES' and f.id_iso639='ES' and p.visible=1
and f.visible=1 and p.produccion=1
and f.produccion=1 order by p.id limit 0,4
SELECT
*
FROM
Pedidos P
INNER JOIN LineasPedido LP ON P.IdPedido = LP.IdPedido
· Welcome [->0]
Log Out
My Account
FAQ
Go Pro!
My Profile
Contacts
Subscriptions
My Stuff
Preferences
Send a Message
Log In
Join TechRepublic
FAQGo Pro!
ZDNet
SmartPlanet
TechRepublic
· On Metacritic: A closer look at LA Noire's pros & cons[->1]
TechRepublic
· Home
Blogs
Downloads
Newsletters
Q&A
Discussions
Training
Research Library
· IT Management
· Development
· IT Support
· Data Center
· Networks
· Security
Leadership
Career
Compliance
IT Consultant
ITIL
Project Management
BusinessIntelligence
Web Development
Software Development
Mobile Development
Help Desk
Desktop Applications
Mobile Computing
Microsoft Windows
Apple
Linux
Cloud Computing
Database Administration
Servers
Storage
Virtualization
LAN/WAN
Wireless
Unified Communications
VoIP
Anti-Malware
Compliance
IT Risk Management
Top of Form 1
Search
Bottom of Form 1
· All ofTechRepublic
· Publications
· Library
Collapse -
[->2]PlayBook: It's for two kinds of people [->3]
[->4]On triathlons and IT management [->5]
[->6]Behind the scenes of Cracking Open [->7]
SQL basics: Query multiple tables
By Shelley Doll
August 12, 2002, 7:00am PDT
Recommend
+1 Vote 19 Comments
10Share[->8]
more +
Add to Favorites
· Del.icio.us
· Digg
· Google Buzz
· Hacker News
· StumbleUpon
· Technorati
It’s sometimes difficult to know which SQL syntax to use when combining data that spans multiple tables. I’ll discuss some of the more frequently used methods for consolidating queries on multiple tables into a single statement.
SQL syntax
If you need a refresher on SQL syntax, readthese articles:
"SQL Basics I: Data queries"[->9] covers database terminology and the four basic query types.
"SQL basics: SELECT statement options"[->10] covers the SELECT statement in detail and explains aggregate functions.
The sample queries in this article adhere to the SQL92 ISO standard. Not all database manufacturers follow this standard, and many have made enhancements that can yieldunexpected results. If you’re uncertain about support for these concepts in your database, please refer to your manufacturer’s documentation.
SELECT
A simple SELECT statement is the most basic way to query multiple tables. You can call more than one table in the FROM clause to combine results from multiple tables. Here’s an example of how this works:
SELECT table1.column1, table2.column2 FROMtable1, table2 WHERE table1.column1 = table2.column1;
In this example, I used dot notation (table1.column1) to specify which table the column came from. If the column in question only appears in one of the referenced tables, you don’t need to include the fully qualified name, but it may be useful to do so for readability.
Tables are separated in the FROM clause by commas. You can include asmany tables as needed, although some databases have a limit to what they can efficiently handle before introducing a formal JOIN statement, which is described below.
This syntax is, in effect, a simple INNER JOIN. Some databases treat it exactly the same as an explicit JOIN. The WHERE clause tells the database which fields to correlate, and it returns results as if the tables listed were...
Regístrate para leer el documento completo.