{"id":147,"date":"2025-08-11T17:49:51","date_gmt":"2025-08-11T15:49:51","guid":{"rendered":"http:\/\/217.160.21.243\/wordpress\/?p=147"},"modified":"2025-08-11T17:49:51","modified_gmt":"2025-08-11T15:49:51","slug":"consultas-sql-con-join","status":"publish","type":"post","link":"https:\/\/www.ccorreas.es\/wordpress\/index.php\/2025\/08\/11\/consultas-sql-con-join\/","title":{"rendered":"Consultas SQL con JOIN"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Dadas dos tablas queremos acceder a los datos de nombre de provincia.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"675\" height=\"301\" src=\"http:\/\/217.160.21.243\/wordpress\/wp-content\/uploads\/2025\/08\/Captura-de-pantalla-2025-08-11-a-las-17.49.40.png\" alt=\"\" class=\"wp-image-149\" srcset=\"https:\/\/www.ccorreas.es\/wordpress\/wp-content\/uploads\/2025\/08\/Captura-de-pantalla-2025-08-11-a-las-17.49.40.png 675w, https:\/\/www.ccorreas.es\/wordpress\/wp-content\/uploads\/2025\/08\/Captura-de-pantalla-2025-08-11-a-las-17.49.40-300x134.png 300w\" sizes=\"auto, (max-width: 675px) 100vw, 675px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>SELECT usuarios.nombre, usuarios.apellidos, provincias.nombre FROM usuarios JOIN provincias ON usuarios.provincia_id = provincias.id<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">SELECT<\/span><span style=\"color: #D8DEE9FF\"> usuarios.nombre, usuarios.apellidos, provincias.nombre <\/span><span style=\"color: #81A1C1\">FROM<\/span><span style=\"color: #D8DEE9FF\"> usuarios <\/span><span style=\"color: #81A1C1\">JOIN<\/span><span style=\"color: #D8DEE9FF\"> provincias <\/span><span style=\"color: #81A1C1\">ON<\/span><span style=\"color: #D8DEE9FF\"> usuarios.provincia_id <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> provincias.id<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">De esta manera obtenemos el nombre de la provincia mediante el id de la provincia almacenado en usuarios.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Dando como resultado lo siguiente:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"916\" height=\"130\" src=\"http:\/\/217.160.21.243\/wordpress\/wp-content\/uploads\/2025\/08\/Captura-de-pantalla-2025-08-11-a-las-17.52.18.png\" alt=\"\" class=\"wp-image-151\" srcset=\"https:\/\/www.ccorreas.es\/wordpress\/wp-content\/uploads\/2025\/08\/Captura-de-pantalla-2025-08-11-a-las-17.52.18.png 916w, https:\/\/www.ccorreas.es\/wordpress\/wp-content\/uploads\/2025\/08\/Captura-de-pantalla-2025-08-11-a-las-17.52.18-300x43.png 300w, https:\/\/www.ccorreas.es\/wordpress\/wp-content\/uploads\/2025\/08\/Captura-de-pantalla-2025-08-11-a-las-17.52.18-768x109.png 768w\" sizes=\"auto, (max-width: 916px) 100vw, 916px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Dadas dos tablas queremos acceder a los datos de nombre de provincia. De esta manera obtenemos el nombre de la [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":148,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-147","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.ccorreas.es\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ccorreas.es\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccorreas.es\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccorreas.es\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccorreas.es\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=147"}],"version-history":[{"count":0,"href":"https:\/\/www.ccorreas.es\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/147\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ccorreas.es\/wordpress\/index.php\/wp-json\/wp\/v2\/media\/148"}],"wp:attachment":[{"href":"https:\/\/www.ccorreas.es\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccorreas.es\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccorreas.es\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}