{"id":225,"date":"2012-02-07T20:02:11","date_gmt":"2012-02-07T20:02:11","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=225"},"modified":"2022-02-17T07:14:05","modified_gmt":"2022-02-17T07:14:05","slug":"querying-across-tables","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/mysql\/queries\/select\/querying-across-tables","title":{"rendered":"Querying Across Tables"},"content":{"rendered":"<p>\n<span style=\"color:#FF0000;\"><em><strong>This is PHP4 Code!<\/strong><\/em><\/span>\n<\/p>\n<h4>\nUsing IN Within A Normal SELECT Query<br \/>\n<\/h4>\n<p>\nYou can select from within another tables results really easily like this:\n<\/p>\n<pre>\r\n<code>\r\n\tSqlCommand1-&gt;CommandText = &quot;SELECT ProjectId \\\r\n\t\t\t\t\t\t\t\tFROM tblMyTable1 \\\r\n\t\t\t\t\t\t\t\tWHERE ProjectIsActive=&#39;TRUE&#39; AND ProjectId IN (SELECT ProjectId FROM tblMyTable2 WHERE ProjectUsersAll=&#39;TRUE&#39; OR UserId=@UserId) \\\r\n\t\t\t\t\t\t\t\tORDER BY ProjectStartDate DESC&quot;;\r\n<\/code><\/pre>\n<h4>\nSimple Find Name From Another Table By Matching An ID Between The Tables<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n$sql = &quot;SELECT table1.name, table2.member_id FROM table1, table2 WHERE table2.member_id = $member_id AND  table1.common_value = table2.common_value ORDER BY table1.name ASC&quot;;\r\n\r\n$result = @mysql_query($sql);\r\n$names_list = &#39;&#39;;\r\n\r\nwhile ($result = @mysql_fetch_array($result))\r\n{\r\n\t$names_list .= $result['name'] . &quot;&lt;br \/&gt;&quot;;\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is PHP4 Code! Using IN Within A Normal SELECT Query You can select from within another tables results really easily like this: SqlCommand1-&gt;CommandText = &quot;SELECT ProjectId \\ FROM tblMyTable1 \\ WHERE ProjectIsActive=&#39;TRUE&#39; AND ProjectId IN (SELECT ProjectId FROM tblMyTable2 WHERE ProjectUsersAll=&#39;TRUE&#39; OR UserId=@UserId) \\ ORDER BY ProjectStartDate DESC&quot;; Simple Find Name From Another Table [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64],"tags":[],"class_list":["post-225","post","type-post","status-publish","format-standard","hentry","category-select"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=225"}],"version-history":[{"count":6,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/225\/revisions"}],"predecessor-version":[{"id":1836,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/225\/revisions\/1836"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}