Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:43 AM
skinhat
 
Posts: n/a
Default SQL statement to select from a drupal webform table

In the following drupal table 'webform_submitted_data' the date
12/8/2007 is specified via 3 records ie:

2 1176718828 0 12
2 1176718828 1 8
2 1176718828 2 2007

I need to be able to select a sid that value matches a certain date.
In the above example the sid value would be '2' if I wanted to select
with date '12/8/2007'. I was wondering if there was a mysql (4.1.21-
standard) SQL statement I could use select all the distinct sid values
that match a certain date. The following is an example of a
'webform_submitted_data' table:

sid cid no data
2 1176015743 0 alison@mailaby.com
2 1176015500 0 alison
2 1176015691 0 money
2 1176718828 0 12
2 1176718828 1 18
2 1176718828 2 2007
2 1176851105 0 1
2 1176851105 1 8
2 1176851105 2 2008
2 1177590862 0 Cheapest flights please 7 adt 6 chd
3 1176015743 0 ijwuishwe@mnqashiu
3 1176015500 0 james
3 1176015691 0 hogh
3 1176718828 0 4
3 1176718828 1 5
3 1176718828 2 2008
3 1176851105 0 4
3 1176851105 1 26
3 1176851105 2 2008
3 1177590862 0 Cheapest easter seats please
4 1176015743 0 jasnbuighe@kjnasiuh
4 1176015500 0 david
4 1176015691 0 wings
4 1176718828 0 12
4 1176718828 1 8
4 1176718828 2 2007
4 1176851105 0 12

This is a drupal table and I would prefer not modify the structure of
it.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 09:43 AM
Captain Paralytic
 
Posts: n/a
Default Re: SQL statement to select from a drupal webform table

On 1 May, 10:36, skinhat <skin...@gmail.com> wrote:
> In the following drupal table 'webform_submitted_data' the date
> 12/8/2007 is specified via 3 records ie:
>
> 2 1176718828 0 12
> 2 1176718828 1 8
> 2 1176718828 2 2007
>
> I need to be able to select a sid that value matches a certain date.
> In the above example the sid value would be '2' if I wanted to select
> with date '12/8/2007'. I was wondering if there was a mysql (4.1.21-
> standard) SQL statement I could use select all the distinct sid values
> that match a certain date. The following is an example of a
> 'webform_submitted_data' table:
>
> sid cid no data
> 2 1176015743 0 ali...@mailaby.com
> 2 1176015500 0 alison
> 2 1176015691 0 money
> 2 1176718828 0 12
> 2 1176718828 1 18
> 2 1176718828 2 2007
> 2 1176851105 0 1
> 2 1176851105 1 8
> 2 1176851105 2 2008
> 2 1177590862 0 Cheapest flights please 7 adt 6 chd
> 3 1176015743 0 ijwuishwe@mnqashiu
> 3 1176015500 0 james
> 3 1176015691 0 hogh
> 3 1176718828 0 4
> 3 1176718828 1 5
> 3 1176718828 2 2008
> 3 1176851105 0 4
> 3 1176851105 1 26
> 3 1176851105 2 2008
> 3 1177590862 0 Cheapest easter seats please
> 4 1176015743 0 jasnbuighe@kjnasiuh
> 4 1176015500 0 david
> 4 1176015691 0 wings
> 4 1176718828 0 12
> 4 1176718828 1 8
> 4 1176718828 2 2007
> 4 1176851105 0 12
>
> This is a drupal table and I would prefer not modify the structure of
> it.


SELECT
DISTINCT `sid`
WHERE LEFT(FROM_UNIXTIME(`cid`),10) = '2007-12-08';

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 09:43 AM
skinhat
 
Posts: n/a
Default Re: SQL statement to select from a drupal webform table


> SELECT
> DISTINCT `sid`
> WHERE LEFT(FROM_UNIXTIME(`cid`),10) = '2007-12-08';


This wouldnt work because the 'cid' field doesnt hold the date. Its
just a unique identifier.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 09:43 AM
J.O. Aho
 
Posts: n/a
Default Re: SQL statement to select from a drupal webform table

skinhat wrote:
>> SELECT
>> DISTINCT `sid`
>> WHERE LEFT(FROM_UNIXTIME(`cid`),10) = '2007-12-08';

>
> This wouldnt work because the 'cid' field doesnt hold the date. Its
> just a unique identifier.
>


Yes, the cid column does hold the date, it's just in a unixtime format and the
FROM_UNIXTIME() function would then convert it to a human readable format

see the mysql documentation:
http://dev.mysql.com/doc/refman/5.0/..._from-unixtime

FROM_UNIXTIME(unix_timestamp), FROM_UNIXTIME(unix_timestamp,format)

Returns a representation of the unix_timestamp argument as a value in
'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS format, depending on whether the
function is used in a string or numeric context. The value is expressed in
the current time zone. unix_timestamp is an internal timestamp value such as
is produced by the UNIX_TIMESTAMP() function.

And then using the ten most left characters in the string would give you just
the YYYY-MM-DD

+------------------------------------+
| LEFT(FROM_UNIXTIME(1176015743),10) |
+------------------------------------+
| 2007-04-08 |
+------------------------------------+


--

//Aho
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 09:43 AM
skinhat
 
Posts: n/a
Default Re: SQL statement to select from a drupal webform table

On May 1, 8:49 pm, "J.O. Aho" <u...@example.net> wrote:
> skinhat wrote:
> >> SELECT
> >> DISTINCT `sid`
> >> WHERE LEFT(FROM_UNIXTIME(`cid`),10) = '2007-12-08';

>
> > This wouldnt work because the 'cid' field doesnt hold the date. Its
> > just a unique identifier.

>
> Yes, the cid column does hold the date, it's just in a unixtime format and the
> FROM_UNIXTIME() function would then convert it to a human readable format
>


Notice in the table these records:


2 1176718828 0 12
2 1176718828 1 18
2 1176718828 2 2007

3 1176718828 0 4
3 1176718828 1 5
3 1176718828 2 2008

Both have the same CID yet represent different dates. The first is
12/18/2007 and the second is 4/5/2008.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 09:43 AM
Captain Paralytic
 
Posts: n/a
Default Re: SQL statement to select from a drupal webform table

On 1 May, 12:03, skinhat <skin...@gmail.com> wrote:
> On May 1, 8:49 pm, "J.O. Aho" <u...@example.net> wrote:
>
> > skinhat wrote:
> > >> SELECT
> > >> DISTINCT `sid`
> > >> WHERE LEFT(FROM_UNIXTIME(`cid`),10) = '2007-12-08';

>
> > > This wouldnt work because the 'cid' field doesnt hold the date. Its
> > > just a unique identifier.

>
> > Yes, the cid column does hold the date, it's just in a unixtime format and the
> > FROM_UNIXTIME() function would then convert it to a human readable format

>
> Notice in the table these records:
>
> 2 1176718828 0 12
> 2 1176718828 1 18
> 2 1176718828 2 2007
>
> 3 1176718828 0 4
> 3 1176718828 1 5
> 3 1176718828 2 2008
>
> Both have the same CID yet represent different dates. The first is
> 12/18/2007 and the second is 4/5/2008.


If they both have the same cid value than it is hardly a "unique"
identifier!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 09:43 AM
skinhat
 
Posts: n/a
Default Re: SQL statement to select from a drupal webform table

On May 1, 9:06 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 1 May, 12:03, skinhat <skin...@gmail.com> wrote:
>
>
>
> > On May 1, 8:49 pm, "J.O. Aho" <u...@example.net> wrote:

>
> > > skinhat wrote:
> > > >> SELECT
> > > >> DISTINCT `sid`
> > > >> WHERE LEFT(FROM_UNIXTIME(`cid`),10) = '2007-12-08';

>
> > > > This wouldnt work because the 'cid' field doesnt hold the date. Its
> > > > just a unique identifier.

>
> > > Yes, the cid column does hold the date, it's just in a unixtime format and the
> > > FROM_UNIXTIME() function would then convert it to a human readable format

>
> > Notice in the table these records:

>
> > 2 1176718828 0 12
> > 2 1176718828 1 18
> > 2 1176718828 2 2007

>
> > 3 1176718828 0 4
> > 3 1176718828 1 5
> > 3 1176718828 2 2008

>
> > Both have the same CID yet represent different dates. The first is
> > 12/18/2007 and the second is 4/5/2008.

>
> If they both have the same cid value than it is hardly a "unique"
> identifier!


The CID is unique to a certain date field. 1176718828 represents a
date where no=0 is the day, no=1 month and no=2 is the year. A SID is
equivalent to a record. This is the way drupal do it (www.drupal.org)
for its webform module for dates.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-28-2008, 09:43 AM
Captain Paralytic
 
Posts: n/a
Default Re: SQL statement to select from a drupal webform table

On 1 May, 12:10, skinhat <skin...@gmail.com> wrote:
> On May 1, 9:06 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>
>
>
>
>
> > On 1 May, 12:03, skinhat <skin...@gmail.com> wrote:

>
> > > On May 1, 8:49 pm, "J.O. Aho" <u...@example.net> wrote:

>
> > > > skinhat wrote:
> > > > >> SELECT
> > > > >> DISTINCT `sid`
> > > > >> WHERE LEFT(FROM_UNIXTIME(`cid`),10) = '2007-12-08';

>
> > > > > This wouldnt work because the 'cid' field doesnt hold the date. Its
> > > > > just a unique identifier.

>
> > > > Yes, the cid column does hold the date, it's just in a unixtime format and the
> > > > FROM_UNIXTIME() function would then convert it to a human readable format

>
> > > Notice in the table these records:

>
> > > 2 1176718828 0 12
> > > 2 1176718828 1 18
> > > 2 1176718828 2 2007

>
> > > 3 1176718828 0 4
> > > 3 1176718828 1 5
> > > 3 1176718828 2 2008

>
> > > Both have the same CID yet represent different dates. The first is
> > > 12/18/2007 and the second is 4/5/2008.

>
> > If they both have the same cid value than it is hardly a "unique"
> > identifier!

>
> The CID is unique to a certain date field. 1176718828 represents a
> date where no=0 is the day, no=1 month and no=2 is the year. A SID is
> equivalent to a record. This is the way drupal do it (www.drupal.org)
> for its webform module for dates.- Hide quoted text -
>
> - Show quoted text -


No you are wrong. Unique means it is the only one of it's kind. This
is not at all unique. It seems to be some sort of field identifier
(that just happens to look like a unix timestamp. Date fields seem to
be identified by a cid of either 1176718828 or 1176851105, whilst
email addresses are identified by a cid of 1176015743, first names by
1176015500, last names by 1176015691, request info by 1177590862 and
so on. It is my guess that the cid of 1176718828 represents one type
of date (e.g. creation date) whilst 1176851105 may represent last
update date (note that these cannot be the correct descriptions as all
the dates are in the future.

I will craft you a self join query that looks at the 1176718828 type
dates, but you need to identify which of the dates it is that are
relevant to you.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-28-2008, 09:43 AM
skinhat
 
Posts: n/a
Default Re: SQL statement to select from a drupal webform table

On May 1, 9:31 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 1 May, 12:10, skinhat <skin...@gmail.com> wrote:
>
>
>
> > On May 1, 9:06 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote:

>
> > > On 1 May, 12:03, skinhat <skin...@gmail.com> wrote:

>
> > > > On May 1, 8:49 pm, "J.O. Aho" <u...@example.net> wrote:

>
> > > > > skinhat wrote:
> > > > > >> SELECT
> > > > > >> DISTINCT `sid`
> > > > > >> WHERE LEFT(FROM_UNIXTIME(`cid`),10) = '2007-12-08';

>
> > > > > > This wouldnt work because the 'cid' field doesnt hold the date. Its
> > > > > > just a unique identifier.

>
> > > > > Yes, the cid column does hold the date, it's just in a unixtime format and the
> > > > > FROM_UNIXTIME() function would then convert it to a human readable format

>
> > > > Notice in the table these records:

>
> > > > 2 1176718828 0 12
> > > > 2 1176718828 1 18
> > > > 2 1176718828 2 2007

>
> > > > 3 1176718828 0 4
> > > > 3 1176718828 1 5
> > > > 3 1176718828 2 2008

>
> > > > Both have the same CID yet represent different dates. The first is
> > > > 12/18/2007 and the second is 4/5/2008.

>
> > > If they both have the same cid value than it is hardly a "unique"
> > > identifier!

>
> > The CID is unique to a certain date field. 1176718828 represents a
> > date where no=0 is the day, no=1 month and no=2 is the year. A SID is
> > equivalent to a record. This is the way drupal do it (www.drupal.org)
> > for its webform module for dates.- Hide quoted text -

>
> > - Show quoted text -

>
> No you are wrong. Unique means it is the only one of it's kind. This
> is not at all unique. It seems to be some sort of field identifier
> (that just happens to look like a unix timestamp. Date fields seem to
> be identified by a cid of either 1176718828 or 1176851105, whilst
> email addresses are identified by a cid of 1176015743, first names by
> 1176015500, last names by 1176015691, request info by 1177590862 and
> so on. It is my guess that the cid of 1176718828 represents one type
> of date (e.g. creation date) whilst 1176851105 may represent last
> update date (note that these cannot be the correct descriptions as all
> the dates are in the future.
>
> I will craft you a self join query that looks at the 1176718828 type
> dates, but you need to identify which of the dates it is that are
> relevant to you.


Thanks. 1176851105 is the other date Im interested in but of course I
can just replace 1176718828 with it.

I consider myself good at SQL and spent quite a long time trying to
get my head around it so if you can do it I'll be in awe at your
skills .

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-28-2008, 09:43 AM
Captain Paralytic
 
Posts: n/a
Default Re: SQL statement to select from a drupal webform table

On 1 May, 12:59, skinhat <skin...@gmail.com> wrote:
> On May 1, 9:31 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>
>
>
>
>
> > On 1 May, 12:10, skinhat <skin...@gmail.com> wrote:

>
> > > On May 1, 9:06 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote:

>
> > > > On 1 May, 12:03, skinhat <skin...@gmail.com> wrote:

>
> > > > > On May 1, 8:49 pm, "J.O. Aho" <u...@example.net> wrote:

>
> > > > > > skinhat wrote:
> > > > > > >> SELECT
> > > > > > >> DISTINCT `sid`
> > > > > > >> WHERE LEFT(FROM_UNIXTIME(`cid`),10) = '2007-12-08';

>
> > > > > > > This wouldnt work because the 'cid' field doesnt hold the date. Its
> > > > > > > just a unique identifier.

>
> > > > > > Yes, the cid column does hold the date, it's just in a unixtime format and the
> > > > > > FROM_UNIXTIME() function would then convert it to a human readable format

>
> > > > > Notice in the table these records:

>
> > > > > 2 1176718828 0 12
> > > > > 2 1176718828 1 18
> > > > > 2 1176718828 2 2007

>
> > > > > 3 1176718828 0 4
> > > > > 3 1176718828 1 5
> > > > > 3 1176718828 2 2008

>
> > > > > Both have the same CID yet represent different dates. The first is
> > > > > 12/18/2007 and the second is 4/5/2008.

>
> > > > If they both have the same cid value than it is hardly a "unique"
> > > > identifier!

>
> > > The CID is unique to a certain date field. 1176718828 represents a
> > > date where no=0 is the day, no=1 month and no=2 is the year. A SID is
> > > equivalent to a record. This is the way drupal do it (www.drupal.org)
> > > for its webform module for dates.- Hide quoted text -

>
> > > - Show quoted text -

>
> > No you are wrong. Unique means it is the only one of it's kind. This
> > is not at all unique. It seems to be some sort of field identifier
> > (that just happens to look like a unix timestamp. Date fields seem to
> > be identified by a cid of either 1176718828 or 1176851105, whilst
> > email addresses are identified by a cid of 1176015743, first names by
> > 1176015500, last names by 1176015691, request info by 1177590862 and
> > so on. It is my guess that the cid of 1176718828 represents one type
> > of date (e.g. creation date) whilst 1176851105 may represent last
> > update date (note that these cannot be the correct descriptions as all
> > the dates are in the future.

>
> > I will craft you a self join query that looks at the 1176718828 type
> > dates, but you need to identify which of the dates it is that are
> > relevant to you.

>
> Thanks. 1176851105 is the other date Im interested in but of course I
> can just replace 1176718828 with it.
>
> I consider myself good at SQL and spent quite a long time trying to
> get my head around it so if you can do it I'll be in awe at your
> skills .- Hide quoted text -
>
> - Show quoted text -


Shucks! Fancy being in awe of little-ole me!

SELECT
DISTINCT `w1`.`sid`
FROM `webf` `w1`
JOIN `webf` `w2` ON `w2`.`cid` = '1176718828'
AND `w1`.`sid` = `w2`.`sid`
AND `w2`.`no` = '2'
JOIN `webf` `w3` ON `w3`.`cid` = '1176718828'
AND `w1`.`sid` = `w3`.`sid`
AND `w3`.`no` = '0'
JOIN `webf` `w4` ON `w4`.`cid` = '1176718828'
AND `w1`.`sid` = `w4`.`sid`
AND `w4`.`no` = '1'
WHERE `w2`.`data` = '2007'
AND `w3`.`data` = '12'
AND `w4`.`data` = '8'

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:05 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446