Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
Digital Lifestyle
Web Design and Hosting
SQL: HAVING question
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="MattSharp" data-source="post: 775951" data-attributes="member: 22022"><p>I have two tables, Table A and Table B. Table B has a foreign key to Table A. Table B has one other column, it's a single character. There can be multiple rows in Table B tied to Table A</p><p></p><p>So you get something like this:</p><p></p><p>[CODE]</p><p>TABLE A</p><p>----------</p><p>ID NAME</p><p>----------</p><p>1 Bill</p><p>2 Tom</p><p>3 Steve</p><p></p><p>TABLE B</p><p>---------</p><p>ID STATUS</p><p>---------</p><p>1 Y</p><p>2 Y</p><p>2 M</p><p>2 N</p><p>3 N</p><p>3 N</p><p>3 Y</p><p>[/CODE]</p><p></p><p>I want to end up getting just 'Y' but not 'M'. So my query should return Bill and Steve.</p><p></p><p>I thought I could do something like this:</p><p></p><p>[CODE]</p><p>SELECT NAME FROM TABLEA</p><p>INNER JOIN TABLEB ON TABLEA.ID=TABLEB.ID </p><p>GROUP BY NAME</p><p>HAVING NOT STATUS='M'</p><p>[/CODE]</p><p></p><p>That doesn't work though. I am thinking there is a way to do this with the HAVING but I can't figure it out. Any ideas?</p></blockquote><p></p>
[QUOTE="MattSharp, post: 775951, member: 22022"] I have two tables, Table A and Table B. Table B has a foreign key to Table A. Table B has one other column, it's a single character. There can be multiple rows in Table B tied to Table A So you get something like this: [CODE] TABLE A ---------- ID NAME ---------- 1 Bill 2 Tom 3 Steve TABLE B --------- ID STATUS --------- 1 Y 2 Y 2 M 2 N 3 N 3 N 3 Y [/CODE] I want to end up getting just 'Y' but not 'M'. So my query should return Bill and Steve. I thought I could do something like this: [CODE] SELECT NAME FROM TABLEA INNER JOIN TABLEB ON TABLEA.ID=TABLEB.ID GROUP BY NAME HAVING NOT STATUS='M' [/CODE] That doesn't work though. I am thinking there is a way to do this with the HAVING but I can't figure it out. Any ideas? [/QUOTE]
Verification
Post reply
Forums
Digital Lifestyle
Web Design and Hosting
SQL: HAVING question
Top