Help with SELECT clause

Help with SELECT clause

am 22.11.2009 07:17:58 von KirAsh4

--0016e6d977c09e94a00478efabd6
Content-Type: text/plain; charset=ISO-8859-1

I'm stuck again ... and perhaps it's just not designed right, but I
inherited this setup, so if anyone has suggestions on how to make it better,
I'm all ears. This is all one table ...

describe approvals;
+-----------+--------------------------+------+-----+------- --+----------------+
| Field | Type | Null | Key | Default |
Extra |
+-----------+--------------------------+------+-----+------- --+----------------+
| id | int(6) | NO | PRI | NULL |
auto_increment |
| photo_uid | int(7) unsigned zerofill | NO | | NULL
| |
| adminname | varchar(100) | NO | | NULL
| |
| status | int(1) | NO | | NULL
| |
+-----------+--------------------------+------+-----+------- --+----------------+


SELECT * FROM approvals;
+----+-----------+-----------+--------+
| id | photo_uid | adminname | status |
+----+-----------+-----------+--------+
| 6 | 0000028 | admin1 | 1 |
| 13 | 0000016 | admin1 | 0 |
| 49 | 0000016 | admin2 | 1 |
| 16 | 0000018 | admin1 | 1 |
| 50 | 0000018 | admin2 | 0 |
+----+-----------+-----------+--------+


The goal, here is to capture everything that does not have 'admin2' in the
adminname column, however duplicated records in the photo_uid column should
also be excluded.

SELECT * FROM approvals WHERE adminname != 'admin2';
+----+-----------+-----------+--------+
| id | photo_uid | adminname | status |
+----+-----------+-----------+--------+
| 6 | 0000028 | admin1 | 1 |
| 13 | 0000016 | admin1 | 0 |
| 16 | 0000018 | admin1 | 1 |
+----+-----------+-----------+--------+


However, I also need to exclude photo_uid '0000016' and '0000018' because
both of them are already tagged by 'admin2'. The only record that needs to
be returned here is '0000028' ...

I just don't know how to do that, or if it's even possible to do in a single
query. I can get it done in two, but I'm hoping for a single query here ...

--0016e6d977c09e94a00478efabd6--

Re:Help with SELECT clause

am 22.11.2009 11:27:54 von shjunsin

------=_Part_92699_14866661.1258885674636
Content-Type: text/plain; charset=gbk
Content-Transfer-Encoding: base64

SGlcSSB0aGluayB5b3UgY2FuIGFjaGlldmUgdGhpcyB1c2luZyBhIHNpbmds ZSBxdWVyeSBsa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IHNpbmds ZSBxdWVyeSBoZXJl
IC4uLgo=
------=_Part_92699_14866661.1258885674636--

Re:Re:Help with SELECT clause

am 22.11.2009 11:44:36 von shjunsin

------=_Part_93420_10246732.1258886676346
Content-Type: text/plain; charset=gbk
Content-Transfer-Encoding: base64

SSdtIHNvcnJ5IGZvciBtaXNzaW5nIHRoZSBrZXkgd29yZCAibm90IiwgaXQg c2hvdWxkIGJlIFNF
TEVDVCAqIEZST00gYXBwcm92YWxzIFdIRVJFIGFkbWlubmFtZSAhPSAnYWRt aW4yJ2FuZCBwaG90
b191aWQgbm90IGluIChzZWxlY3QgcGhvdG9fdWlkIGZyb20gYXBwcm92YWxz IHdoZXJlIGFkbWlu
bmFtZT0nYWRtaW4yJyksCgoKCgrU2jIwMDktMTEtMjKjrHNoanVuc2luIDxz aGp1bnNpbkAxNjMu
Y29tPiDQtLXAo7oKPkhpXEkgdGhpbmsgeW91IGNhbiBhY2hpZXZlIHRoaXMg dXNpbmcgYSBzaW5n
bGUgcXVlcnkgbGlrZSB0aGlzOiBTRUxFQ1QgKiBGUk9NIGFwcHJvdmFscyBX SEVSRSBhZG1pbm5h
bWUgIT0gJ2FkbWluMidhbmQgcGhvdG9fdWlkIGluIChzZWxlY3QgcGhvdG9f dWlkIGZyb20gYXBw
cm92YWxzIHdoZXJlIGFkbWlubmFtZT0nYWRtaW4yJyksIG9mIGNvdXJzZSwg bWF5YmUgaXQncyBu
b3QgdGhlIGJlc3Qgc29sdXRpb24sIGp1c3QgZm9yIHlvdXIgaW5mb3JtYXRp b24u1NoyMDA5LTEx
LTIyo6wiQXNobGV5IE0uIEtpcmNobmVyIiA8a2lyYXNoNEBnbWFpbC5jb20+ INC0tcCjugo+Pkkn
bSBzdHVjayBhZ2FpbiAuLi4gYW5kIHBlcmhhcHMgaXQncyBqdXN0IG5vdCBk ZXNpZ25lZCByaWdo
dCwgYnV0IEkKPj5pbmhlcml0ZWQgdGhpcyBzZXR1cCwgc28gaWYgYW55b25l IGhhcyBz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